How to use the prance.util.fs.read_file function in prance

To help you get started, we’ve selected a few prance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def petstore_yaml():
  from prance.util import fs
  return fs.read_file('tests/OpenAPI-Specification/examples/v2.0/yaml/petstore.yaml')
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def get_specs(fname):
  specs = fs.read_file(fname)

  from prance.util import formats
  specs = formats.parse_spec(specs, fname)

  return specs
github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def petstore_json():
  from prance.util import fs
  return fs.read_file('tests/OpenAPI-Specification/examples/v2.0/json/petstore.json')
github jfinkhaeuser / prance / tests / test_cli.py View on Github external
with runner.isolated_filesystem():
      result = runner.invoke(cli.convert,
          [os.path.join(curdir, 'tests/specs/petstore.yaml'), outname])
      assert result.exit_code == 0

      # There also must be a 'foo' file now.
      files = [f for f in os.listdir('.') if os.path.isfile(f)]
      assert outname in files

      # Ensure a UTF-8 file encoding.
      from prance.util import fs
      assert 'utf-8' in fs.detect_encoding(outname, default_to_utf8 = False,
                                           read_all = True)

      # Now do a full encoding detection, too
      contents = fs.read_file(outname)
      assert 'openapi' in contents
      assert '3.' in contents
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_load_utf8bom():
  contents = fs.read_file('tests/specs/utf8bom.yaml')
  assert contents.index(u'söme välüe') >= 0, 'UTF-8 BOM handling failed!'
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_load_nobom():
  contents = fs.read_file('tests/specs/petstore.yaml')
  assert contents.index(u'Swagger Petstore') >= 0, 'File reading failed!'
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_write_file(tmpdir):
  with sandbox.sandbox(tmpdir):
    test_text = u'söme täxt'
    fs.write_file('test.out', test_text)

    # File must have been written
    files = [f for f in os.listdir('.') if os.path.isfile(f)]
    assert 'test.out' in files

    # File contents must work
    contents = fs.read_file('test.out')
    assert test_text == contents
github jfinkhaeuser / prance / prance / util / url.py View on Github external
cache, return the cache contents.
  :return: The resource text of the URL, and the content type.
  :rtype: tuple
  """
  url_key = 'text_' + urlresource(url)
  entry = cache.get(url_key, None)
  if entry is not None:
    return entry

  # Fetch contents according to scheme. We assume requests can handle all the
  # non-file schemes, or throw otherwise.
  content = None
  content_type = None
  if url.scheme in (None, '', 'file'):
    from .fs import read_file, from_posix
    content = read_file(from_posix(url.path))
  elif url.scheme == 'python':
    # Resolve package path
    package = url.netloc
    path = url.path
    if path[0] == '/':
      path = path[1:]

    import pkg_resources
    path = pkg_resources.resource_filename(package, path)

    from .fs import read_file, from_posix
    content = read_file(from_posix(path))
  else:
    import requests
    response = requests.get(url.geturl())
    if not response.ok:  # pragma: nocover