def __init__(self): tmp_root_path = Path(func_locker.get_temp_dir()).joinpath(func_locker.TEMP_ROOT_DIR) tmp_root_path.mkdir(parents=True, exist_ok=True) self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.counter', dir=tmp_root_path) self.file_name = self.file.name self.file.write(b'0') self.file.close()
def _get_function_lock_path(name, scope_context=None, class_name=None): ls = [get_temp_dir(), TEMP_ROOT_DIR, TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE] if scope_context: ls.append(scope_context) ls.append('{0}.{1}'.format(_get_function_name_string(name, class_name), LOCK_FILE_NAME_EXT)) return os.path.join(*ls)
def _get_function_lock_path(name, scope_context=None, class_name=None): ls = [get_temp_dir(), TEMP_ROOT_DIR, TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE] if scope_context: ls.append(scope_context) ls.append('{0}.{1}'.format(_get_function_name_string(name, class_name), LOCK_FILE_NAME_EXT) ) return os.path.join(*ls)
def test_scoped_with_locking(self): """Ensure that the lock file was created at the right location""" simple_scoped_locking_function() lock_file_path = os.path.join( get_temp_dir(), TEMP_ROOT_DIR, TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE_TEST_2, SCOPE_2, '{}.simple_scoped_locking_function.lock'.format( _this_module_name_string)) self.assertTrue(os.path.exists(lock_file_path))
def __init__(self): tmp_root_path = os.path.join(func_locker.get_temp_dir(), func_locker.TEMP_ROOT_DIR) if not os.path.exists(tmp_root_path): os.mkdir(tmp_root_path) self.file = tempfile.NamedTemporaryFile(delete=False, suffix='.counter', dir=tmp_root_path) self.file_name = self.file.name self.file.write(b'0') self.file.close()
def _get_function_lock_path(name, scope_context=None, class_name=None): ls = [ func_locker.get_temp_dir(), func_locker.TEMP_ROOT_DIR, func_locker.TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE, ] if scope_context: ls.append(scope_context) func_name_string = _get_function_name_string(name, class_name) ls.append(f'{func_name_string}.{func_locker.LOCK_FILE_NAME_EXT}') return os.path.join(*ls)
def test_scoped_with_locking(self): """Ensure that the lock file was created at the right location""" simple_scoped_locking_function() lock_file_path = os.path.join( func_locker.get_temp_dir(), func_locker.TEMP_ROOT_DIR, func_locker.TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE_TEST_2, SCOPE_2, f'{_this_module_name_string}.simple_scoped_locking_function.lock', ) assert os.path.exists(lock_file_path)
def test_scoped_with_locking(self): """Ensure that the lock file was created at the right location""" simple_scoped_locking_function() lock_file_path = os.path.join( get_temp_dir(), TEMP_ROOT_DIR, TEMP_FUNC_LOCK_DIR, NAMESPACE_SCOPE_TEST_2, SCOPE_2, '{}.simple_scoped_locking_function.lock'.format( _this_module_name_string) ) self.assertTrue(os.path.exists(lock_file_path))
def _init_counter_file(): global _counter_file_name tmp_root_path = os.path.join(get_temp_dir(), TEMP_ROOT_DIR) if not os.path.exists(tmp_root_path): os.mkdir(tmp_root_path) _counter_file = tempfile.NamedTemporaryFile(delete=False, suffix='.counter', dir=tmp_root_path) _counter_file_name = _counter_file.name _counter_file.write('0'.encode('utf-8')) _counter_file.close()
def _init_counter_file(): global _counter_file_name tmp_root_path = os.path.join(get_temp_dir(), TEMP_ROOT_DIR) if not os.path.exists(tmp_root_path): os.mkdir(tmp_root_path) _counter_file = tempfile.NamedTemporaryFile( delete=False, suffix='.counter', dir=tmp_root_path ) _counter_file_name = _counter_file.name _counter_file.write('0'.encode('utf-8')) _counter_file.close()