Skip to content

Commit 7d3822e

Browse files
committed
Added tests
1 parent ef60424 commit 7d3822e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

openapi_spec_validator/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ def main():
3232
else:
3333
print('OK')
3434

35+
3536
if __name__ == '__main__':
3637
main()

tests/integration/test_main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from unittest import mock
2+
3+
from openapi_spec_validator.__main__ import main
4+
5+
6+
@mock.patch('openapi_spec_validator.__main__.sys')
7+
def test_nonexisting_file(mock_sys):
8+
"""Calling with non-existing file should sys.exit."""
9+
# the first parameter is always the name of the program itself, so
10+
# we can insert a dummy here
11+
testargs = ['progname', 'i_dont_exist.yaml']
12+
with mock.patch('sys.argv', testargs):
13+
assert mock_sys.exit.assert_called
14+
15+
16+
@mock.patch('openapi_spec_validator.__main__.sys')
17+
def test_happy_path(mock_sys):
18+
testargs = ['progname', './tests/integration/data/v3.0/petstore.yaml']
19+
with mock.patch('sys.argv', testargs):
20+
main()
21+
assert not mock_sys.exit.called

0 commit comments

Comments
 (0)