|
| 1 | +import pytest |
| 2 | + |
| 3 | +from openapi_spec_validator.__main__ import main |
| 4 | + |
| 5 | + |
| 6 | +def test_schema_default(): |
| 7 | + """Test default schema is 3.0.0""" |
| 8 | + testargs = ['./tests/integration/data/v3.0/petstore.yaml'] |
| 9 | + main(testargs) |
| 10 | + |
| 11 | + |
| 12 | +def test_schema_v3(): |
| 13 | + """No errors when calling proper v3 file.""" |
| 14 | + testargs = ['--schema', '3.0.0', |
| 15 | + './tests/integration/data/v3.0/petstore.yaml'] |
| 16 | + main(testargs) |
| 17 | + |
| 18 | + |
| 19 | +def test_schema_v2(): |
| 20 | + """No errors when calling with proper v2 file.""" |
| 21 | + testargs = ['--schema', '2.0', |
| 22 | + './tests/integration/data/v2.0/petstore.yaml'] |
| 23 | + main(testargs) |
| 24 | + |
| 25 | + |
| 26 | +def test_schema_unknown(): |
| 27 | + """Errors on running with unknown schema.""" |
| 28 | + testargs = ['--schema', 'x.x', |
| 29 | + './tests/integration/data/v2.0/petstore.yaml'] |
| 30 | + with pytest.raises(SystemExit): |
| 31 | + main(testargs) |
| 32 | + |
| 33 | + |
| 34 | +def test_validation_error(): |
| 35 | + """SystemExit on running with ValidationError.""" |
| 36 | + testargs = ['--schema', '3.0.0', |
| 37 | + './tests/integration/data/v2.0/petstore.yaml'] |
| 38 | + with pytest.raises(SystemExit): |
| 39 | + main(testargs) |
| 40 | + |
| 41 | + |
| 42 | +def test_nonexisting_file(): |
| 43 | + """Calling with non-existing file should sys.exit.""" |
| 44 | + testargs = ['i_dont_exist.yaml'] |
| 45 | + with pytest.raises(SystemExit): |
| 46 | + main(testargs) |
0 commit comments