예제 #1
0
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
예제 #2
0
def get_specs(fname):
  specs = fs.read_file(fname)

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

  return specs
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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
예제 #8
0
def petstore_json():
    from prance.util import fs
    return fs.read_file(
        'tests/OpenAPI-Specification/examples/v2.0/json/petstore.json')
예제 #9
0
def petstore_yaml():
    from prance.util import fs
    return fs.read_file(
        'tests/OpenAPI-Specification/examples/v2.0/yaml/petstore.yaml')
예제 #10
0
def test_load_utf8bom_override():
    with pytest.raises(UnicodeDecodeError):
        fs.read_file("tests/specs/utf8bom.yaml", "ascii")
예제 #11
0
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!"
예제 #12
0
def test_load_nobom():
    contents = fs.read_file("tests/specs/petstore.yaml")
    assert contents.index("Swagger Petstore") >= 0, "File reading failed!"
예제 #13
0
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!'
예제 #14
0
def test_load_nobom():
    contents = fs.read_file('tests/specs/petstore.yaml')
    assert contents.index(u'Swagger Petstore') >= 0, 'File reading failed!'
예제 #15
0
def test_load_utf8bom_override():
    with pytest.raises(UnicodeDecodeError):
        fs.read_file('tests/utf8bom.yaml', 'ascii')