Ejemplo n.º 1
0
def a_request():
    request = MagicMock()
    request.method = "post"
    request.url = "http://{}.com".format(a_string())
    request.headers = {a_string(): a_string()}
    request.body = a_string()
    return request
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_get_numeric_channels_values(self):
        # when
        client = MagicMock()
        client.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 = [Bunch(id=a_uuid_string(), name='epoch_loss')]
        experiment.channelsLastValues = [Bunch(channelName='epoch_loss', x=2.5, y=2)]

        client.get_experiment.return_value = experiment

        # then
        experiment = Experiment(
            client=client,
            _id=a_string(),
            internal_id=a_uuid_string(),
            project_full_id="test/sandbox"
        )
        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 a_refresh_token():
    return jwt.encode(
        {
            'exp': 0,
            'azp': a_string(),
            'iss': 'http://{}.com'.format(a_string())
        }, SECRET)
def an_access_token():
    return jwt.encode(
        {
            'exp': time.time(),
            'azp': a_string(),
            'iss': 'http://{}.com'.format(a_string())
        }, SECRET)
Ejemplo n.º 6
0
def a_refresh_token():
    return jwt.encode(
        {
            "exp": 0,
            "azp": a_string(),
            "iss": "http://{}.com".format(a_string())
        }, SECRET)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def setUp(self):
     super(TestProject, self).setUp()
     self.backend = MagicMock()
     self.project = Project(backend=self.backend,
                            internal_id=a_uuid_string(),
                            namespace=a_string(),
                            name=a_string())
     self.current_directory = os.getcwd()
Ejemplo n.º 9
0
def a_channel():
    x = random.randint(0, 100)
    return Munch(id=a_uuid_string(),
                 name=a_string(),
                 channelType='text',
                 lastX=x,
                 x=x,
                 y=a_string())
Ejemplo n.º 10
0
def an_access_token():
    return jwt.encode(
        {
            "exp": time.time(),
            "azp": a_string(),
            "iss": "http://{}.com".format(a_string()),
        },
        SECRET,
    )
Ejemplo n.º 11
0
def a_parameter():
    p = MagicMock()
    p.id = a_uuid_string()
    p.name = a_string()
    p.parameterType = 'double'
    p.value = str(uniform(-100, 100))
    return p
Ejemplo n.º 12
0
def a_registered_project_member(username=None):
    if username is None:
        username = a_string()

    registered_member_info = MagicMock()
    registered_member_info.avatarSource = 'default'
    registered_member_info.avatarUrl = ''
    registered_member_info.firstName = a_string()
    registered_member_info.lastName = a_string()
    registered_member_info.username = username

    project_member = MagicMock()
    project_member.invitationInfo = None
    project_member.registeredMemberInfo = registered_member_info
    project_member.role = 'manager'

    return project_member
Ejemplo n.º 13
0
def a_channel_value():
    cv = MagicMock()
    cv.channelId = a_uuid_string()
    cv.channelName = a_string()
    cv.channelType = 'numeric'
    cv.x = uniform(1, 100)
    cv.y = str(uniform(1, 100))
    return cv
Ejemplo n.º 14
0
def an_invited_project_member():
    invitation_info = MagicMock()
    invitation_info.id = a_uuid_string()
    invitation_info.email = a_string() + '@example.com'

    project_member = MagicMock()
    project_member.invitationInfo = invitation_info
    project_member.registeredMemberInfo = None
    project_member.role = 'member'

    return project_member
Ejemplo n.º 15
0
    def test_get_members(self):
        # given
        member_usernames = [a_string() for _ in range(0, 2)]
        members = [a_registered_project_member(username) for username in member_usernames]

        # and
        self.backend.get_project_members.return_value = members + [an_invited_project_member()]

        # when
        fetched_member_usernames = self.project.get_members()

        # then
        self.backend.get_project_members.assert_called_once_with(self.project.internal_id)

        # and
        self.assertEqual(member_usernames, fetched_member_usernames)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    def test_get_string_attribute(self):
        for container_id, container_type in self.ids_with_types:
            with self.subTest(f"For containerType: {container_type}"):
                # given
                text = a_string()
                self.backend.execute_operations(
                    container_id,
                    container_type,
                    operations=[AssignString(["x"], text)])

                # when
                ret = self.backend.get_string_attribute(container_id,
                                                        container_type,
                                                        path=["x"])

                # then
                self.assertEqual(StringAttribute(text), ret)
Ejemplo n.º 18
0
def a_property():
    p = MagicMock()
    p.key = a_string()
    p.value = a_string()
    return p
Ejemplo n.º 19
0
def a_project():
    project = MagicMock()
    project.id = a_uuid_string()
    project.name = a_string()
    return project
Ejemplo n.º 20
0
def an_experiment_leaderboard_entry_dto():
    entry = MagicMock()
    entry.entryType = 'experiment'
    entry.id = a_uuid_string()
    entry.shortId = a_string()
    entry.projectId = a_uuid_string()
    entry.state = 'succeeded'
    entry.experimentStates = an_experiment_states(succeeded=1)
    entry.responding = True
    entry.name = a_string()
    entry.organizationName = a_string()
    entry.projectName = a_string()
    entry.description = a_string()
    entry.timeOfCreation = a_timestamp()
    entry.timeOfCompletion = a_timestamp()
    entry.runningTime = randint(1, 1000)
    entry.owner = a_string()
    entry.size = randint(1, 1000)
    entry.tags = [a_string(), a_string()]
    entry.environment = a_string()
    entry.workerType = a_string()
    entry.hostname = a_string()
    entry.sourceSize = randint(1, 1000)
    entry.sourceMd5 = a_string()
    entry.commitId = a_string()
    entry.properties = [a_property(), a_property()]
    entry.parameters = [a_parameter(), a_parameter()]
    entry.channelsLastValues = [a_channel_value(), a_channel_value()]
    entry.trashed = False
    entry.deleted = False
    entry.isBestExperiment = False
    return entry
Ejemplo n.º 21
0
 def setUp(self):
     super(TestProject, self).setUp()
     self.client = MagicMock()
     self.project = Project(client=self.client, internal_id=a_uuid_string(), namespace=a_string(), name=a_string())
Ejemplo n.º 22
0
 def setUp(self):
     super(TestProject, self).setUp()
     self.backend = MagicMock()
     self.project = Project(backend=self.backend, internal_id=a_uuid_string(), namespace=a_string(), name=a_string())