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_process_invalid_versions(self):
fp = NamedTemporaryFile(suffix=".py", delete=False)
fp.write(b"long(42)\n") # long is a v2 feature: 2.0 !3
fp.write(b"breakpoint()\n") # breakpoint(): !2, 3.7
fp.close()
proc_res = process_individual((fp.name, self.config))
self.assertEqual(proc_res.mins, None)
self.assertTrue(proc_res.text.startswith("Versions could not be combined"))
self.assertEmpty(proc_res.bps)
os.remove(fp.name)
def test_process_file_not_Found(self):
if current_version() >= 3.0:
exc = FileNotFoundError
else:
exc = Exception
with self.assertRaises(exc):
process_individual(("nonexistent", self.config))
def test_process_file_using_backport(self):
fp = NamedTemporaryFile(suffix=".py", delete=False)
fp.write(b"import typing\n")
fp.close()
proc_res = process_individual((fp.name, self.config))
self.assertEmpty(proc_res.text)
self.assertEqualItems(["typing"], proc_res.bps)
os.remove(fp.name)
def test_process_runtests_py(self):
proc_res = process_individual((sys.argv[0], self.config))
self.assertEqual(basename(proc_res.path), "runtests.py")
self.assertEqual(proc_res.mins, [(2, 7), (3, 0)])
self.assertEmpty(proc_res.text)
self.assertEmpty(proc_res.bps)
def test_process_syntax_error(self):
# Syntax error triggers minimum versions [0, 0].
fp = NamedTemporaryFile(suffix=".py", delete=False)
fp.write(b"(") # SyntaxError: unexpected EOF while parsing
fp.close()
proc_res = process_individual((fp.name, self.config))
self.assertEqual(proc_res.mins, [(0, 0), (0, 0)])
self.assertEmpty(proc_res.text)
self.assertEmpty(proc_res.bps)
os.remove(fp.name)