File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -32,5 +32,6 @@ def main():
3232 else :
3333 print ('OK' )
3434
35+
3536if __name__ == '__main__' :
3637 main ()
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments