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_probably_python_file(self):
tmp_fld = mkdtemp()
self.assertTrue(probably_python_file(touch(tmp_fld, "test.py")))
self.assertTrue(probably_python_file(touch(tmp_fld, "test.pyw")))
self.assertFalse(probably_python_file(touch(tmp_fld, "test.pyc")))
# Empty file isn't python.
f = touch(tmp_fld, "test")
self.assertFalse(probably_python_file(f))
# Magic line.
with open(f, mode="w") as fp:
fp.write("#!/usr/bin/env python\n")
self.assertTrue(probably_python_file(f))
# Binary file isn't python code.
f = touch(tmp_fld, "binary")
with open(f, mode="wb") as fp:
fp.write(b"\x80\x89\x90")
self.assertFalse(probably_python_file(f))
def test_probably_python_file(self):
tmp_fld = mkdtemp()
self.assertTrue(probably_python_file(touch(tmp_fld, "test.py")))
self.assertTrue(probably_python_file(touch(tmp_fld, "test.pyw")))
self.assertFalse(probably_python_file(touch(tmp_fld, "test.pyc")))
# Empty file isn't python.
f = touch(tmp_fld, "test")
self.assertFalse(probably_python_file(f))
# Magic line.
with open(f, mode="w") as fp:
fp.write("#!/usr/bin/env python\n")
self.assertTrue(probably_python_file(f))
# Binary file isn't python code.
f = touch(tmp_fld, "binary")
with open(f, mode="wb") as fp:
fp.write(b"\x80\x89\x90")
self.assertFalse(probably_python_file(f))
rmtree(tmp_fld)
def test_probably_python_file(self):
tmp_fld = mkdtemp()
self.assertTrue(probably_python_file(touch(tmp_fld, "test.py")))
self.assertTrue(probably_python_file(touch(tmp_fld, "test.pyw")))
self.assertFalse(probably_python_file(touch(tmp_fld, "test.pyc")))
# Empty file isn't python.
f = touch(tmp_fld, "test")
self.assertFalse(probably_python_file(f))
# Magic line.
with open(f, mode="w") as fp:
fp.write("#!/usr/bin/env python\n")
self.assertTrue(probably_python_file(f))
# Binary file isn't python code.
f = touch(tmp_fld, "binary")
with open(f, mode="wb") as fp:
fp.write(b"\x80\x89\x90")
self.assertFalse(probably_python_file(f))
def test_probably_python_file(self):
tmp_fld = mkdtemp()
self.assertTrue(probably_python_file(touch(tmp_fld, "test.py")))
self.assertTrue(probably_python_file(touch(tmp_fld, "test.pyw")))
self.assertFalse(probably_python_file(touch(tmp_fld, "test.pyc")))
# Empty file isn't python.
f = touch(tmp_fld, "test")
self.assertFalse(probably_python_file(f))
# Magic line.
with open(f, mode="w") as fp:
fp.write("#!/usr/bin/env python\n")
self.assertTrue(probably_python_file(f))
# Binary file isn't python code.
f = touch(tmp_fld, "binary")
with open(f, mode="wb") as fp:
fp.write(b"\x80\x89\x90")
self.assertFalse(probably_python_file(f))
rmtree(tmp_fld)