def main(): '''Command line utility which execute and parse df command''' parser = argparse.ArgumentParser() parser.add_argument("--human", action='store_true', help="Display filesystems statistics\ in human-readable format") parser.add_argument("--inode", action='store_true', help="Getting information about inode's\ in a filesystems") try: args = parser.parse_args() if args.human: result = HumanExecutor().execute() elif args.inode: result = InodeExecutor().execute() else: result = BaseExecutor().execute() except Exception as error: result = BaseExecutor().result(None, str(error), 1) finally: if result: print(result) with open("result.json", "w") as f: f.write(result)
def setUp(self): """creation of two test strings - one with data, second with error""" self.testobj = BaseExecutor().result(test_data.TEST_RESULT_OUTPUT, test_data.ERROR_MESSAGE_OK, test_data.RETURN_CODE_OK) self.testobj_error = BaseExecutor().result( None, test_data.ERROR_MESSAGE_IF_ERROR, test_data.RETURN_CODE_ERROR)
def test_command_maker(self): """testing of the correct convertation list of args from *args""" self.assertEqual(BaseExecutor().cmd, 'df') self.assertEqual( BaseExecutor('ls', 'arg1', 'arg2').args, ('arg1', 'arg2')) self.assertIsInstance(BaseExecutor('df', '-i').command_maker(), list) self.assertEqual( BaseExecutor('df', 'h', 'r', 'q').command_maker(), ['df', 'h', 'r', 'q'], 'Error in command_maker() method')
def test_add_metric(self): bexec = BaseExecutor(HoleDirection.H) assert bexec.metrics.empty is True bexec.add_metric(operation="test_operation", name="test_name", seconds=30, count=10) assert bexec.metrics.empty is False expected = { "executor": "base", "operation": "test_operation", "name": "test_name", "seconds": 30, "count": 10, "hole_direction": HoleDirection.H, } actual = bexec.metrics.iloc[0].to_dict() assert expected == actual
def test_executor_init(self): bexec = BaseExecutor(HoleDirection.H) assert bexec.metrics.empty is True assert {*bexec.metrics.columns} == { "seconds", "executor", "hole_direction", "operation", "name", "count", } assert bexec.download_kwargs == {} assert bexec.process_kwargs == {} assert bexec.persist_kwargs == {}
def test_init_validate_hole_dir(self): bexec = BaseExecutor("H") assert bexec.hole_dir is HoleDirection.H with pytest.raises(ValueError): BaseExecutor("BAD")
def test_repr(self): assert repr(BaseExecutor(HoleDirection.H)) == "BaseExecutor[H]"
def bexec(self): yield BaseExecutor(HoleDirection.H)