def test_stateloader_should_load_existing_state(tmpdir): state.dump({'pids': [1,2]}) s = state.load() assert isinstance(s, State) assert [1,2] == s.pids
def test_stateloader_should_load_existing_state(tmpdir): state.dump({'pids': [1, 2]}) s = state.load() assert isinstance(s, State) assert [1, 2] == s.pids
def handle(self): nodes = self.load_state() if 'all' in self.args.nodes: for node, info in nodes.iteritems(): print 'Killing node {0} with pid {1}'.format(node, info['pid']) os.kill(info['pid'], 15) state.clear() else: for node in self.args.nodes: info = nodes.pop(node) print 'Killing node {0} with pid {1}'.format(node, info['pid']) os.kill(info['pid'], 15) state.dump(nodes)
def test_dump_should_persist_state_in_file(): s = State() s.database = 'mongodb' s.pids = [123, 312] state.dump(s) try: with open(state.filename) as fileobj: data = json.load(fileobj) except TypeError: pytest.fail("%r should not be empty" % state.filename) except ValueError: pytest.fail("%r should be JSON" % state.filename) assert {'database': 'mongodb', 'pids': [123, 312]} == data
def save_state(self, nodes): state.dump(nodes)
def test_clear_should_remove_state_file(): state.dump({'foo': 'bar'}) assert os.path.isfile(state.filename) state.clear() assert not os.path.isfile(state.filename)