def test_key_names_must_match_tag_names(self): container = TagContainer() tag1 = Tag('type') tag2 = Tag('name') container.data = {'fake': tag1, 'name': tag2} container.validate() assert not container.valid assert "Tag 'type' has wrong key: 'fake'" in container.problems
def test_ignores_if_key_exists(self): container = TagContainer() tag1 = Tag('type', 'human') tag2 = Tag('type', 'werewolf') container.append(tag1) container.append(tag2) assert container('type') == tag1
def test_iterate_all_yields_values(): container = TagContainer() tag1 = Tag('type') tag2 = Tag('name') container.append(tag1) container.append(tag2) tag_list = list(container.all()) assert tag1 in tag_list assert tag2 in tag_list
def test_present_includes_only_present_tags(): container = TagContainer() tag1 = Tag('type', 'human') tag2 = Tag('name') container.append(tag1) container.append(tag2) present_tags = container.present() assert 'type' in present_tags assert 'name' not in present_tags
def test_names_includes_all_tag_names(): container = TagContainer() tag1 = Tag('type', 'human') tag2 = Tag('name') container.append(tag1) container.append(tag2) names = list(container.names()) assert 'type' in names assert 'name' in names
def test_container_inherits_tag_errors(self): container = TagContainer() tag = Tag('type', limit=0, required=True) container.append(tag) container.validate() assert not container.valid assert "Tag 'type' is required but limited to zero values" in container.problems
def test_subtag_doesnt_match(self): bad_subtag = Tag('rank') tag = GroupTag('employer', subtag='job') tag.data['bobsburgers'] = bad_subtag tag.validate() assert not tag.valid assert "Tag 'employer' uses subtag 'job', but found 'rank' for 'bobsburgers'" in tag.problems
def test_preserves_attributes(self): tag = Tag('type', 'value1', 'value2', 'value3', required=True, hidden=True, limit=5) tag2 = tag.tagslice(0, 1) assert tag2.required == tag.required assert tag2.hidden == tag.hidden assert tag2.limit == tag.limit
def test_limit_zero_and_required_dont_mix(self): tag = Tag('type', 'asdf', required=True, limit=0) tag.validate() assert not tag.valid assert "Tag 'type' is required but limited to zero values" in tag.problems
def test_required_with_no_values_fails(self): tag = Tag('type', required=True) tag.validate() assert not tag.valid
def test_present_with_values_set(self): tag = Tag('type', 'asdf') assert tag.present assert tag
def test_filled_with_values_set(self): tag = Tag('type', 'asdf') assert tag.filled assert tag
def test_append_ignores_empty_values(): tag = Tag('type') tag.append(' \t ') assert tag.filled is False
def test_updates_hidden_values_from_tag(self): origin_tag = Tag('type', 'human', 'werewolf') origin_tag.hidden_values.append('werewolf') tag = Tag('type') tag.update(origin_tag) assert 'werewolf' in tag.hidden_values
def test_matches_partial_values(self): tag = Tag('type', 'value1', 'value2', 'value3') assert tag.contains('val')
def test_hide_partial_value_does_nothing(self): tag = Tag('type', 'value1', 'value2', 'value3', hidden=False) tag.hide_value('val') tag.sanitize() assert tag.data == ['value1', 'value2', 'value3']
def test_touch_shows_error(capsys): tag = Tag('type') tag.touch() _, err = capsys.readouterr() assert "Calling touch() on non-flag class Tag object 'type'" in err
def test_returns_string_if_present(self): tag = Tag('type', 'value1', 'value2') assert tag.first_value() == 'value1'
def test_saves_default_values(): tag = Tag('type', 'asdf', '1234') assert 'asdf' in tag assert '1234' in tag
def test_returns_none_if_no_values(self): tag = Tag('type') assert tag.first_value() is None
def test_filled_data_ignores_empties(): tag = Tag('type') tag.append(' \t ') tag.append('human') assert tag.filled_data == ['human']
def test_bool_truthy_when_present(): tag = Tag('type') assert not tag tag.append('human') assert tag
def test_not_filled_with_no_values(self): tag = Tag('type') assert not tag.filled assert not tag
def test_when_hidden_removes_all_values(self): tag = Tag('type', 'value1', 'value2', 'value3', hidden=True) tag.sanitize() assert not tag
def test_not_present_with_no_values(self): tag = Tag('type') assert not tag.present assert not tag
def test_updates_hidden_from_tag(self): origin_tag = Tag('type') origin_tag.hidden = True tag = Tag('type') tag.update(origin_tag) assert tag.hidden
def test_required_with_values_passes(self): tag = Tag('type', 'asdf', required=True) tag.validate() assert tag.valid
def test_when_not_hidden_removes_nothing(self): tag = Tag('type', 'value1', 'value2', 'value3', hidden=False) tag.sanitize() assert tag.data == ['value1', 'value2', 'value3']
def test_hidden_values_must_exist(self): tag = Tag('type', 'value1') tag.hide_value('value2') tag.validate() assert not tag.valid assert "Value 'value2' for tag 'type' cannot be hidden, because it does not exist" in tag.problems
def test_hide_present_value_removes_value(self): tag = Tag('type', 'value1', 'value2', 'value3', hidden=False) tag.hide_value('value2') tag.sanitize() assert tag.data == ['value1', 'value3']