def test_magic_args(alfred4): """Magic args""" # cache original sys.argv oargs = sys.argv[:] # delsettings sys.argv = [oargs[0]] + [b"workflow:delsettings"] try: wf = Workflow(default_settings={"arg1": "value1"}) assert wf.settings["arg1"] == "value1" assert os.path.exists(wf.settings_path) with pytest.raises(SystemExit): wf.args assert not os.path.exists(wf.settings_path) finally: sys.argv = oargs[:] # delcache sys.argv = [oargs[0]] + [b"workflow:delcache"] def somedata(): return {"arg1": "value1"} try: wf = Workflow() cachepath = wf.cachefile("somedir") os.makedirs(cachepath) wf.cached_data("test", somedata) assert os.path.exists(wf.cachefile("test.pickle")) with pytest.raises(SystemExit): wf.args assert not os.path.exists(wf.cachefile("test.pickle")) finally: sys.argv = oargs[:]
def test_magic_args(alfred4): """Magic args""" # cache original sys.argv oargs = sys.argv[:] # delsettings sys.argv = [oargs[0]] + [b'workflow:delsettings'] try: wf = Workflow(default_settings={'arg1': 'value1'}) assert wf.settings['arg1'] == 'value1' assert os.path.exists(wf.settings_path) with pytest.raises(SystemExit): wf.args assert not os.path.exists(wf.settings_path) finally: sys.argv = oargs[:] # delcache sys.argv = [oargs[0]] + [b'workflow:delcache'] def somedata(): return {'arg1': 'value1'} try: wf = Workflow() cachepath = wf.cachefile('somedir') os.makedirs(cachepath) wf.cached_data('test', somedata) assert os.path.exists(wf.cachefile('test.cpickle')) with pytest.raises(SystemExit): wf.args assert not os.path.exists(wf.cachefile('test.cpickle')) finally: sys.argv = oargs[:]
def test_delete_cache(info2): """Magic: delete cache""" with WorkflowMock(['script', 'workflow:delcache']): wf = Workflow() testpath = wf.cachefile('file.test') with open(testpath, 'wb') as fp: fp.write('test!') assert os.path.exists(testpath) # Process magic arguments wf.args assert not os.path.exists(testpath)
def test_delete_cache(infopl): """Magic: delete cache""" with WorkflowMock(["script", "workflow:delcache"]): wf = Workflow() testpath = wf.cachefile("file.test") with open(testpath, "w") as fp: fp.write("test!") assert os.path.exists(testpath) # Process magic arguments wf.args assert not os.path.exists(testpath) wf.reset()
class BackgroundTests(unittest.TestCase): def setUp(self): self.wf = Workflow() def _pidfile(self, name): return self.wf.cachefile('{}.pid'.format(name)) def _write_pidfile(self, name, pid): pidfile = self._pidfile(name) with open(pidfile, 'wb') as file: file.write('{}'.format(pid)) def _delete_pidfile(self, name): pidfile = self._pidfile(name) if os.path.exists(pidfile): os.unlink(pidfile) def test_no_pidfile(self): """No pidfile""" self.assertFalse(is_running('boomstick')) def test_non_existent_process(self): """Non-existent process""" self._write_pidfile('test', 9999999) self.assertFalse(is_running('test')) self.assertFalse(os.path.exists(self._pidfile('test'))) def test_existing_process(self): """Existing process""" self._write_pidfile('test', os.getpid()) self.assertTrue(is_running('test')) self.assertTrue(os.path.exists(self._pidfile('test'))) self._delete_pidfile('test') def test_run_in_background(self): """Run in background""" cmd = ['sleep', '1'] run_in_background('test', cmd) sleep(0.5) self.assertTrue(is_running('test')) self.assertTrue(os.path.exists(self._pidfile('test'))) self.assertEqual(run_in_background('test', cmd), None) sleep(0.6) self.assertFalse(is_running('test')) self.assertFalse(os.path.exists(self._pidfile('test')))
def test_reset(info2): """Magic: reset""" with WorkflowMock(['script', 'workflow:reset']): wf = Workflow() wf.settings['key'] = 'value' datatest = wf.datafile('data.test') cachetest = wf.cachefile('cache.test') settings_path = wf.datafile('settings.json') for p in (datatest, cachetest): with open(p, 'wb') as file_obj: file_obj.write('test!') for p in (datatest, cachetest, settings_path): assert os.path.exists(p) # Process magic arguments wf.args for p in (datatest, cachetest, settings_path): assert not os.path.exists(p)
def test_reset(infopl): """Magic: reset""" with WorkflowMock(["script", "workflow:reset"]): wf = Workflow() wf.settings["key"] = "value" datatest = wf.datafile("data.test") cachetest = wf.cachefile("cache.test") settings_path = wf.datafile("settings.json") for p in (datatest, cachetest): with open(p, "w") as file_obj: file_obj.write("test!") for p in (datatest, cachetest, settings_path): assert os.path.exists(p) # Process magic arguments wf.args for p in (datatest, cachetest, settings_path): assert not os.path.exists(p) wf.reset()
#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2014 [email protected] # # MIT Licence. See http://opensource.org/licenses/MIT # # Created on 2014-07-03 # """Common settings.""" from __future__ import unicode_literals from workflow import Workflow wf = Workflow() INDEX_DB = wf.cachefile('index.db') DATA_FILE = wf.cachefile('gitlab.json')
#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2014 [email protected] # # MIT Licence. See http://opensource.org/licenses/MIT # # Created on 2014-07-03 # """Common settings.""" from __future__ import unicode_literals from workflow import Workflow wf = Workflow() INDEX_DB = wf.cachefile('index.db') DATA_FILE = wf.workflowfile('books.tsv')