示例#1
0
    def testLogBasicComponentRun(self):
        # Create component then log a run of it
        create_component("test_component", "test_description", "shreya")

        # Create a ComponentRun
        cr = ComponentRun(component_name="test_component")
        cr.set_start_timestamp()
        cr.code_snapshot = b"def main(): return"
        cr.add_inputs(["duplicate_input", "duplicate_input"])
        cr.add_outputs(["duplicate_output", "duplicate_output"])
        cr.set_end_timestamp()

        # Log component run
        log_component_run(cr)
示例#2
0
    def testLogKVComponentRun(self):
        # Tests implementation of values in iopointer
        create_component(
            name="valtest",
            description="Tests implementation of values in iopointer.",
            owner="me",
        )

        iop1 = ["this", "is", "the", "first"]
        iop2 = ["this", "is", "the", "second"]

        # Create iopointers and CR
        iop1 = IOPointer(name="iop1", value=iop1)
        iop2 = IOPointer(name="iop2", value=iop2)

        cr = ComponentRun("valtest")
        cr.set_start_timestamp()
        cr.set_end_timestamp()
        cr.add_input(iop1)
        cr.add_output(iop2)
        log_component_run(cr)
示例#3
0
class TestComponentRun(unittest.TestCase):
    def setUp(self):
        self.mock_component_run = ComponentRun("mock_component_run")
        self.mock_component_run_dict = {
            "component_name": "mock_component_run",
            "notes": "",
            "inputs": [],
            "outputs": [],
            "git_hash": None,
            "git_tags": None,
            "code_snapshot": None,
            "start_timestamp": None,
            "end_timestamp": None,
            "dependencies": [],
            "id": None,
            "stale": [],
            "test_result": None,
            "mlflow_run_id": None,
            "mlflow_run_params": None,
            "mlflow_run_metrics": None,
        }

        self.mock_inputs = [
            IOPointer("mock_input_1"),
            IOPointer("mock_input_2"),
        ]
        self.mock_outputs = [
            IOPointer("mock_output_1"),
            IOPointer("mock_output_2"),
        ]

    def testSerialize(self):
        """
        Test the serialization functionality.
        """
        self.assertEqual(
            self.mock_component_run.to_dictionary(),
            self.mock_component_run_dict,
        )

    def testSetStartEndError(self):
        """
        Test that setting start and end ts as non
        datetime types throws an error.
        """

        with self.assertRaises(TypeError):
            self.mock_component_run.set_start_timestamp("incorrect_type")

        with self.assertRaises(TypeError):
            self.mock_component_run.set_end_timestamp("incorrect_type")

    def testAddInputOutput(self):
        cr = copy.deepcopy(self.mock_component_run)
        for inp in self.mock_inputs:
            cr.add_input(inp)
        for out in self.mock_outputs:
            cr.add_output(out)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))
        self.assertEqual(cr.outputs, list(set(self.mock_outputs)))

    def testAddInputsOutputs(self):
        cr = copy.deepcopy(self.mock_component_run)
        cr.add_inputs(self.mock_inputs)
        cr.add_outputs(self.mock_outputs)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))
        self.assertEqual(cr.outputs, list(set(self.mock_outputs)))

    def testAddDuplicateInputs(self):
        cr = copy.deepcopy(self.mock_component_run)
        cr.add_inputs(self.mock_inputs)
        cr.add_inputs(self.mock_inputs)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))

    def testAddNotes(self):
        cr = copy.deepcopy(self.mock_component_run)
        expected_output = "this is a test note"
        cr.notes = "this is a test note"

        self.assertEqual(cr.notes, expected_output)

    def testAddNotesError(self):
        """
        Test that adding non-str input to the notes attribute
        gives a TypeError
        """
        with self.assertRaises(TypeError):
            self.mock_component_run.notes = ["incorrect_type"]
示例#4
0
class TestComponentRun(unittest.TestCase):
    def setUp(self):
        self.mock_component_run = ComponentRun("mock_component_run")
        self.mock_component_run_dict = {
            "component_name": "mock_component_run",
            "inputs": [],
            "outputs": [],
            "git_hash": None,
            "code_snapshot": None,
            "start_timestamp": None,
            "end_timestamp": None,
            "dependencies": [],
            "id": None,
            "stale": [],
        }

        self.mock_inputs = [IOPointer("mock_input_1"), IOPointer("mock_input_2")]
        self.mock_outputs = [IOPointer("mock_output_1"), IOPointer("mock_output_2")]

    def testSerialize(self):
        """
        Test the serialization functionality.
        """
        self.assertEqual(
            self.mock_component_run.to_dictionary(), self.mock_component_run_dict
        )

    def testSetStartEndError(self):
        """
        Test that setting start and end ts as non datetime types throws an error.
        """

        with self.assertRaises(TypeError):
            self.mock_component_run.set_start_timestamp("incorrect_type")

        with self.assertRaises(TypeError):
            self.mock_component_run.set_end_timestamp("incorrect_type")

    def testAddInputOutput(self):
        cr = copy.deepcopy(self.mock_component_run)
        for inp in self.mock_inputs:
            cr.add_input(inp)
        for out in self.mock_outputs:
            cr.add_output(out)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))
        self.assertEqual(cr.outputs, list(set(self.mock_outputs)))

    def testAddInputsOutputs(self):
        cr = copy.deepcopy(self.mock_component_run)
        cr.add_inputs(self.mock_inputs)
        cr.add_outputs(self.mock_outputs)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))
        self.assertEqual(cr.outputs, list(set(self.mock_outputs)))

    def testAddDuplicateInputs(self):
        cr = copy.deepcopy(self.mock_component_run)
        cr.add_inputs(self.mock_inputs)
        cr.add_inputs(self.mock_inputs)

        self.assertEqual(cr.inputs, list(set(self.mock_inputs)))