def test_convert_output(runner): from prance import cli import os, os.path curdir = os.getcwd() outnames = ["foo.json", "foo.yaml"] for outname in outnames: 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
def get_specs(fname): specs = fs.read_file(fname) from prance.util import formats specs = formats.parse_spec(specs, fname) return specs
def test_write_file(tmpdir): with sandbox.sandbox(tmpdir): test_text = "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
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
def test_write_file_bom(tmpdir): with sandbox.sandbox(tmpdir): test_text = "söme täxt" fs.write_file("test.out", test_text, "utf-8-sig") # File must have been written files = [f for f in os.listdir(".") if os.path.isfile(f)] assert "test.out" in files # Encoding must match the one we've given encoding = fs.detect_encoding("test.out") assert encoding == "utf-8-sig" # File contents must work contents = fs.read_file("test.out") assert test_text == contents
def test_write_file_bom(tmpdir): with sandbox.sandbox(tmpdir): test_text = u'söme täxt' fs.write_file('test.out', test_text, 'utf-8-sig') # File must have been written files = [f for f in os.listdir('.') if os.path.isfile(f)] assert 'test.out' in files # Encoding must match the one we've given encoding = fs.detect_encoding('test.out') assert encoding == 'utf-8-sig' # File contents must work contents = fs.read_file('test.out') assert test_text == contents
def test_write_file(): # What we're doing here has really nothing to do with click's CliRunner, # but since we have it, we might as well use its sandboxing feature. from click.testing import CliRunner runner = CliRunner() with runner.isolated_filesystem(): 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
def petstore_json(): from prance.util import fs return fs.read_file( 'tests/OpenAPI-Specification/examples/v2.0/json/petstore.json')
def petstore_yaml(): from prance.util import fs return fs.read_file( 'tests/OpenAPI-Specification/examples/v2.0/yaml/petstore.yaml')
def test_load_utf8bom_override(): with pytest.raises(UnicodeDecodeError): fs.read_file("tests/specs/utf8bom.yaml", "ascii")
def test_load_utf8bom(): contents = fs.read_file("tests/specs/utf8bom.yaml") assert contents.index("söme välüe") >= 0, "UTF-8 BOM handling failed!"
def test_load_nobom(): contents = fs.read_file("tests/specs/petstore.yaml") assert contents.index("Swagger Petstore") >= 0, "File reading failed!"
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!'
def test_load_nobom(): contents = fs.read_file('tests/specs/petstore.yaml') assert contents.index(u'Swagger Petstore') >= 0, 'File reading failed!'
def test_load_utf8bom_override(): with pytest.raises(UnicodeDecodeError): fs.read_file('tests/utf8bom.yaml', 'ascii')