from test import script_helper
-def _iter_files(name):
- for f in (name + os.extsep + "py",
- name + os.extsep + "pyc",
- name + os.extsep + "pyo",
- name + os.extsep + "pyw",
- name + "$py.class"):
- yield f
+def _files(name):
+ return (name + os.extsep + "py",
+ name + os.extsep + "pyc",
+ name + os.extsep + "pyo",
+ name + os.extsep + "pyw",
+ name + "$py.class")
def chmod_files(name):
- for f in _iter_files(name):
+ for f in _files(name):
try:
os.chmod(f, 0o600)
except OSError as exc:
raise
def remove_files(name):
- for f in _iter_files(name):
+ for f in _files(name):
unlink(f)
rmtree('__pycache__')
# Now delete the source file and check the pyc was rewritten
unlink(fname)
unload(TESTFN)
+ if __debug__:
+ bytecode_name = fname + "c"
+ else:
+ bytecode_name = fname + "o"
+ os.rename(imp.cache_from_source(fname), bytecode_name)
m3 = __import__(TESTFN)
self.assertEqual(m3.x, 'rewritten')
finally: