File tree Expand file tree Collapse file tree 2 files changed +12
-18
lines changed
Expand file tree Collapse file tree 2 files changed +12
-18
lines changed Original file line number Diff line number Diff line change 1313)
1414
1515
16- def main ():
16+ def main (args = None ):
1717 parser = argparse .ArgumentParser ()
1818 parser .add_argument ('filename' , help = "Absolute or relative path to file" )
19- args = parser .parse_args ()
19+ args = parser .parse_args (args )
2020 filename = args .filename
2121 filename = os .path .abspath (filename )
2222 try :
Original file line number Diff line number Diff line change 1- from unittest import mock
1+ import pytest
22
33from openapi_spec_validator .__main__ import main
44
55
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- main ()
14- assert mock_sys .exit .called
6+ def test_happy_path ():
7+ """No errors when calling with proper file."""
8+ testargs = ['./tests/integration/data/v3.0/petstore.yaml' ]
9+ main (testargs )
1510
1611
17- @mock .patch ('openapi_spec_validator.__main__.sys' )
18- def test_happy_path (mock_sys ):
19- testargs = ['progname' , './tests/integration/data/v3.0/petstore.yaml' ]
20- with mock .patch ('sys.argv' , testargs ):
21- main ()
22- assert not mock_sys .exit .called
12+ def test_nonexisting_file ():
13+ """Calling with non-existing file should sys.exit."""
14+ testargs = ['i_dont_exist.yaml' ]
15+ with pytest .raises (SystemExit ):
16+ main (testargs )
You can’t perform that action at this time.
0 commit comments