| 1216 | return os.path.join(self.tmp_dir, self.module_name) |
| 1217 | |
| 1218 | def update_lib(self, lib_name): |
| 1219 | for modname in list(sys.modules): |
| 1220 | if modname.startswith(self.module_name): |
| 1221 | del sys.modules[modname] |
| 1222 | path = os.path.join(self.lib_paths[lib_name], "__init__.py") |
| 1223 | self.lib_count[lib_name] += 1 |
| 1224 | with salt.utils.files.fopen(path, "wb") as fh: |
| 1225 | fh.write( |
| 1226 | salt.utils.stringutils.to_bytes( |
| 1227 | submodule_lib_template.format(count=self.lib_count[lib_name]) |
| 1228 | ) |
| 1229 | ) |
| 1230 | fh.flush() |
| 1231 | os.fsync(fh.fileno()) # flush to disk |
| 1232 | |
| 1233 | # pyc files don't like it when we change the original quickly |
| 1234 | # since the header bytes only contain the timestamp (granularity of seconds) |
| 1235 | # TODO: don't write them? Is *much* slower on re-load (~3x) |
| 1236 | # https://docs.python.org/2/library/sys.html#sys.dont_write_bytecode |
| 1237 | remove_bytecode(path) |
| 1238 | |
| 1239 | @pytest.mark.slow_test |
| 1240 | def test_basic(self): |