def test_cli(): with pytest.raises(SystemExit): cli.main(['-v']) with pytest.raises(SystemExit): # no settings.py cli.main(['-l']) from ant_nest import _settings_example as settings # mock settings.py import sys.modules['settings'] = settings settings.ANT_PACKAGES = ['NoAnts'] with pytest.raises(ModuleNotFoundError): # can`t import NoAnts cli.main(['-l']) settings.ANT_PACKAGES = ['ant_nest.things'] with pytest.raises(SystemExit): # no ants can be found cli.main(['-l']) settings.ANT_PACKAGES = ['tests'] cli.main(['-l']) with pytest.raises(SystemExit): # FakeAnt not exist cli.main(['-a' 'FakeAnt']) cli.main(['-l']) with pytest.raises(SystemExit), mock.patch('os.mkdir', lambda x: None), \ mock.patch('shutil.copyfile', lambda *args: None): cli.main(['-c' '.']) cli.main(['-a' 'tests.test_things.CliAnt'])
def test_cli(): httpbin_base_url = os.getenv("TEST_HTTPBIN", "http://localhost:8080/") with pytest.raises(SystemExit): cli.main(["-v"]) with pytest.raises(SystemExit): # no settings.py cli.main(["-l"]) with pytest.raises(SystemExit), mock.patch( "IPython.embed"): # no settings.py cli.main(["-u", httpbin_base_url]) from ant_nest import _settings_example as settings # mock settings.py import sys.modules["settings"] = settings settings.ANT_PACKAGES = ["NoAnts"] with pytest.raises(ModuleNotFoundError): # can`t import NoAnts cli.main(["-l"]) settings.ANT_PACKAGES = ["ant_nest.things"] with pytest.raises(SystemExit): # no ants can be found cli.main(["-l"]) settings.ANT_PACKAGES = ["tests"] cli.main(["-l"]) with pytest.raises(SystemExit): # FakeAnt not exist cli.main(["-a" "FakeAnt"]) cli.main(["-l"]) with pytest.raises(SystemExit), mock.patch("os.mkdir", lambda x: None), mock.patch( "shutil.copyfile", lambda *args: None): cli.main(["-c" "."]) cli.main(["-a" "tests.test_things.CliAnt"])