def test_storage_path_context_lock(self): app = Swarm(__name__, instance_path='temp') storage = app.storage('state', 'subprocess') pth = os.path.abspath(storage) with storage.locked(): self.assertTrue(os.path.exists('../subprocess.lock')) shutil.rmtree('temp')
def test_storage_path_context(self): app = Swarm(__name__, instance_path='temp') storage = app.storage('state', 'subprocess') initial = os.path.abspath(os.curdir) pth = os.path.abspath(storage) with storage: self.assertTrue(os.path.exists(pth)) self.assertTrue(os.path.abspath(os.curdir) == pth) self.assertTrue(os.path.abspath(os.curdir) == initial) shutil.rmtree('temp')
def test_open(self): app = Swarm(__name__, instance_path='temp') storage = app.storage('state', 'subprocess') with storage.open('test.txt', 'w') as test: test.write('asd') with open('temp/state/subprocess/test.txt', 'r') as test: self.assertTrue(test.read() == 'asd') shutil.rmtree('temp')
def test_locked_open(self): app = Swarm(__name__, instance_path='temp') storage = app.storage('state', 'subprocess') with storage.open('test.txt', 'w', locked=True) as test: test.write('asd') self.assertTrue(os.path.exists(os.path.join(storage, 'test.txt.lock'))) with open('temp/state/subprocess/test.txt', 'r') as test: self.assertTrue(test.read() == 'asd') shutil.rmtree('temp')
def test_storage_path(self): app = Swarm(__name__, instance_path='temp') storage = app.storage('state', 'subprocess') self.assertFalse(os.path.exists('temp'))
def test_folder_with_default_instance_path(self): app = Swarm(__name__) self.assertTrue(app.storage('state', 'subprocess') \ == os.path.abspath('var/test_fs_vault-instance/state/subprocess'))