Beispiel #1
0
    def test_send_image(self, ChannelsValuesSender, content):
        # given
        channels_values_sender = ChannelsValuesSender.return_value
        experiment = Experiment(mock.MagicMock(), a_project(),
                                an_experiment_id(), a_uuid_string())
        image_value = dict(
            name=a_string(),
            description=a_string(),
            data=base64.b64encode(content()).decode("utf-8"),
        )
        channel_value = ChannelValue(x=random.randint(0, 100),
                                     y=dict(image_value=image_value),
                                     ts=time.time())

        # when
        experiment.send_image(
            "errors",
            channel_value.x,
            "/tmp/img.png",
            image_value["name"],
            image_value["description"],
            channel_value.ts,
        )

        # then
        channels_values_sender.send.assert_called_with("errors",
                                                       ChannelType.IMAGE.value,
                                                       channel_value)
Beispiel #2
0
    def test_append_tags(self):
        # given
        backend = mock.MagicMock()
        experiment = Experiment(backend, a_project(), an_experiment_id(),
                                a_uuid_string())

        # and
        def build_call(tags_list):
            return call(experiment=experiment,
                        tags_to_add=tags_list,
                        tags_to_delete=[])

        # when
        experiment.append_tag("tag")
        experiment.append_tag(["tag1", "tag2", "tag3"])
        experiment.append_tag("tag1", "tag2", "tag3")
        experiment.append_tags("tag")
        experiment.append_tags(["tag1", "tag2", "tag3"])
        experiment.append_tags("tag1", "tag2", "tag3")

        # then
        backend.update_tags.assert_has_calls([
            build_call(["tag"]),
            build_call(["tag1", "tag2", "tag3"]),
            build_call(["tag1", "tag2", "tag3"]),
            build_call(["tag"]),
            build_call(["tag1", "tag2", "tag3"]),
            build_call(["tag1", "tag2", "tag3"]),
        ])
Beispiel #3
0
    def test_get_numeric_channels_values(self):
        # when
        backend = MagicMock()
        backend.get_channel_points_csv.return_value = StringIO(u"\n".join(
            ["0.3,2.5", "1,2"]))

        experiment = MagicMock()
        experiment.id = a_string()
        experiment.internal_id = a_uuid_string()
        experiment.channels = [Munch(id=a_uuid_string(), name="epoch_loss")]
        experiment.channelsLastValues = [
            Munch(channelName="epoch_loss", x=2.5, y=2)
        ]

        backend.get_experiment.return_value = experiment

        # then
        experiment = Experiment(
            backend=backend,
            project=a_project(),
            _id=a_string(),
            internal_id=a_uuid_string(),
        )
        result = experiment.get_numeric_channels_values("epoch_loss")

        expected_result = pd.DataFrame(
            {
                "x": [0.3, 1.0],
                "epoch_loss": [2.5, 2.0]
            }, dtype=float)

        expected_result = sort_df_by_columns(expected_result)
        result = sort_df_by_columns(result)

        assert_frame_equal(expected_result, result)
    def test_delete_artifact(self):
        # given
        backend = mock.MagicMock()
        project = a_project()
        experiment = Experiment(
            backend,
            project,
            an_experiment_id(),
            a_uuid_string()
        )

        # and
        def build_call(path):
            return call(
                experiment=experiment,
                path=path
            )

        # when
        experiment.delete_artifacts('/an_abs_path_in_exp_output')
        experiment.delete_artifacts('/../an_abs_path_in_exp')
        experiment.delete_artifacts('/../../an_abs_path_in_prj')
        experiment.delete_artifacts('a_path_in_exp_output')
        self.assertRaises(ValueError, experiment.delete_artifacts, 'test/../../a_path_outside_exp')
        self.assertRaises(ValueError, experiment.delete_artifacts, '../a_path_outside_exp')
        self.assertRaises(ValueError, experiment.delete_artifacts, "..")

        # then
        backend.rm_data.assert_has_calls([
            build_call('/an_abs_path_in_exp_output'),
            build_call('/../an_abs_path_in_exp'),
            build_call('/../../an_abs_path_in_prj'),
            build_call('a_path_in_exp_output'),
        ])
Beispiel #5
0
    def test_send_text(self, ChannelsValuesSender):
        # given
        channels_values_sender = ChannelsValuesSender.return_value
        experiment = Experiment(mock.MagicMock(), a_project(),
                                an_experiment_id(), a_uuid_string())
        channel_value = ChannelValue(x=random.randint(0, 100),
                                     y=dict(text_value=a_string()),
                                     ts=time.time())

        # when
        experiment.send_text("stdout", channel_value.x,
                             channel_value.y["text_value"], channel_value.ts)

        # then
        channels_values_sender.send.assert_called_with("stdout",
                                                       ChannelType.TEXT.value,
                                                       channel_value)