Skip to content

Commit

Permalink
Support adding more then one tag in single call (#83)
Browse files Browse the repository at this point in the history
Closes: #82
  • Loading branch information
aniezurawski authored Apr 5, 2019
1 parent 5c2b28c commit 49cc4fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
11 changes: 9 additions & 2 deletions neptune/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,18 @@ def get_system_properties(self):
def get_tags(self):
return self._client.get_experiment(self._internal_id).tags

def append_tag(self, tag):
def append_tag(self, tag, *tags):
if isinstance(tag, list):
tags_list = tag
else:
tags_list = [tag] + list(tags)
self._client.update_tags(experiment=self,
tags_to_add=[tag],
tags_to_add=tags_list,
tags_to_delete=[])

def append_tags(self, tag, *tags):
self.append_tag(tag, *tags)

def remove_tag(self, tag):
self._client.update_tags(experiment=self,
tags_to_add=[],
Expand Down
33 changes: 32 additions & 1 deletion tests/neptune/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import mock
import pandas as pd
from mock import MagicMock
from mock import call, MagicMock
from munch import Munch
from pandas.util.testing import assert_frame_equal

Expand Down Expand Up @@ -101,6 +101,37 @@ def test_send_image(self, ChannelsValuesSender, content):
# then
channels_values_sender.send.assert_called_with('errors', ChannelType.IMAGE.value, channel_value)

def test_append_tags(self):
# given
client = mock.MagicMock()
experiment = Experiment(client, an_experiment_id(), a_uuid_string(), a_project_qualified_name())

#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
client.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'])
])

def test_get_numeric_channels_values(self):
# when
client = MagicMock()
Expand Down

0 comments on commit 49cc4fe

Please sign in to comment.