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_hides_single_subvalue(self): tag = GroupTag('type', 'value1', 'value2', hidden=False) tag.subtag('value2').append('cart') tag.subtag('value2').append('blart') tag.subtag('value2').hide_value('cart') header = tag.to_header() assert '@hide type >> value2 >> cart' in header
def test_preserves_attributes(self): tag = GroupTag('employer', '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_inserts_from_group_tag(self): tag = GroupTag('group') tag2 = GroupTag('group') tag2.append('funny') tag2['funny'].append('giggles') tag.update(tag2) assert 'funny' in tag assert 'giggles' in tag['funny']
def test_filled_with_values_set(self): tag = GroupTag('employer', 'fruitco') assert tag.filled assert tag
def test_leaves_old_values(self): tag = GroupTag('group') tag.update(['werewolves']) tag.update(['humans', 'monkeys']) assert 'humans' in tag assert 'werewolves' in tag
def test_limit_zero_and_required_dont_mix(self): tag = GroupTag('employer', 'fruitco', required=True, limit=0) tag.validate() assert not tag.valid assert "Tag 'employer' is required but limited to zero values" in tag.problems
def test_present_with_values_set(self): tag = GroupTag('employer', 'fruitco') assert tag.present assert tag
def test_required_with_no_values_fails(self): tag = GroupTag('employer', required=True) tag.validate() assert not tag.valid
def test_bool_truthy_when_present(): tag = GroupTag('type') assert not tag tag.append('human') assert tag
def test_when_hidden_removes_all_values(self): tag = GroupTag('group', 'value1', 'value2', 'value3', hidden=True) tag.sanitize() assert not tag
def test_returns_string_if_present(self): tag = GroupTag('type', 'value1', 'value2') assert tag.first_value() == 'value1'
def test_returns_none_if_no_values(self): tag = GroupTag('type') assert tag.first_value() is None
def test_matches_subvalues(self): tag = GroupTag('group', 'value1', 'value2', 'value3') tag['value1'].append('subval1') assert tag.contains('subval1')
def test_matches_partial_values(self): tag = GroupTag('group', 'value1', 'value2', 'value3') assert tag.contains('val')
def test_matches_wrong_case(self): tag = GroupTag('group', 'value1', 'value2', 'value3') assert tag.contains('VALUE1')
def test_saves_list_values(self): tag = GroupTag('group', 'guys', 'dolls') assert 'guys' in tag assert 'dolls' in tag
def test_when_not_hidden_removes_nothing(self): tag = GroupTag('group', 'value1', 'value2', 'value3', hidden=False) tag.sanitize() assert list(tag) == ['value1', 'value2', 'value3']
def test_not_filled_with_no_values(self): tag = GroupTag('employer') assert not tag.filled assert not tag
def test_hides_all_subtags(self): tag = GroupTag('group', 'value1', 'value2', 'value3', hidden=False) tag.subtag('value1').append('subvalue') tag.subtag('value1').hidden = True tag.sanitize() assert not tag.subtag('value1')
def test_not_present_with_no_values(self): tag = GroupTag('employer') assert not tag.present assert not tag
def test_hidden_values_must_exist(self): tag = GroupTag('employer', 'value1') tag.hide_value('value2') tag.validate() assert not tag.valid assert "Value 'value2' for tag 'employer' cannot be hidden, because it does not exist" in tag.problems
def test_required_with_values_passes(self): tag = GroupTag('employer', 'fruitco', required=True) tag.validate() assert tag.valid
def test_adds_value_to_keys(self): tag = GroupTag('employer') tag.append('bobsburgers') assert 'bobsburgers' in tag
def test_hide_present_value_removes_value(self): tag = GroupTag('group', 'value1', 'value2', 'value3', hidden=False) tag.hide_value('value2') tag.sanitize() assert list(tag) == ['value1', 'value3']
def test_wildcard_with_any_values_is_true(self): tag = GroupTag('group', 'value1', 'value2', 'value3') assert tag.contains('*')
def test_saves_keyword_values(self): tag = GroupTag('group', guys=Tag('rank'), dolls=Tag('rank')) assert 'guys' in tag assert 'dolls' in tag
def test_hide_partial_value_does_nothing(self): tag = GroupTag('group', 'value1', 'value2', 'value3', hidden=False) tag.hide_value('val') tag.sanitize() assert list(tag) == ['value1', 'value2', 'value3']
def test_add_group_creates_group_object(self): container = TagContainer() container.add_group('group', 'club') assert 'group' in container assert container('group') == GroupTag('group', 'club')
def test_touch_shows_error(capsys): tag = GroupTag('group') tag.touch() _, err = capsys.readouterr() assert "Calling touch() on non-flag class GroupTag object 'group'" in err