Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_main_no_rules_hit(self):
# Python file that doesn't hit any rules should exit successfully.
fp = NamedTemporaryFile(suffix=".py", delete=False)
fp.close()
with self.assertRaises(SystemExit) as ex:
sys.argv = [sys.argv[0], fp.name]
main()
os.remove(fp.name)
sys.argv = [sys.argv[0]]
self.assertEqual(ex.exception.code, 0)
def test_main_no_args(self):
# Print usage and exit with code 1.
with self.assertRaises(SystemExit) as ex:
main()
self.assertEqual(ex.exception.code, 1)
def test_main_target_not_met(self):
# Ensure exit code 1 when target isn't met.
fp = NamedTemporaryFile(suffix=".py", delete=False)
fp.close()
with self.assertRaises(SystemExit) as ex:
sys.argv = [sys.argv[0], "-t=3.0", fp.name]
main()
os.remove(fp.name)
sys.argv = [sys.argv[0]]
self.assertEqual(ex.exception.code, 1)
def test_main_no_paths(self):
# The path doesn't exist and isn't a .py file which means no paths are detected.
with self.assertRaises(SystemExit) as ex:
sys.argv = [sys.argv[0], "nonexistentfilethatisntpy"]
main()
sys.argv = [sys.argv[0]]
self.assertEqual(ex.exception.code, 1)