예제 #1
0
 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
예제 #2
0
    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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
 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
예제 #9
0
 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
예제 #10
0
 def test_required_with_no_values_fails(self):
     tag = Tag('type', required=True)
     tag.validate()
     assert not tag.valid
예제 #11
0
 def test_present_with_values_set(self):
     tag = Tag('type', 'asdf')
     assert tag.present
     assert tag
예제 #12
0
 def test_filled_with_values_set(self):
     tag = Tag('type', 'asdf')
     assert tag.filled
     assert tag
예제 #13
0
def test_append_ignores_empty_values():
    tag = Tag('type')
    tag.append(' \t ')
    assert tag.filled is False
예제 #14
0
 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
예제 #15
0
 def test_matches_partial_values(self):
     tag = Tag('type', 'value1', 'value2', 'value3')
     assert tag.contains('val')
예제 #16
0
 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']
예제 #17
0
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
예제 #18
0
 def test_returns_string_if_present(self):
     tag = Tag('type', 'value1', 'value2')
     assert tag.first_value() == 'value1'
예제 #19
0
def test_saves_default_values():
    tag = Tag('type', 'asdf', '1234')
    assert 'asdf' in tag
    assert '1234' in tag
예제 #20
0
 def test_returns_none_if_no_values(self):
     tag = Tag('type')
     assert tag.first_value() is None
예제 #21
0
def test_filled_data_ignores_empties():
    tag = Tag('type')
    tag.append(' \t ')
    tag.append('human')
    assert tag.filled_data == ['human']
예제 #22
0
def test_bool_truthy_when_present():
    tag = Tag('type')
    assert not tag
    tag.append('human')
    assert tag
예제 #23
0
 def test_not_filled_with_no_values(self):
     tag = Tag('type')
     assert not tag.filled
     assert not tag
예제 #24
0
 def test_when_hidden_removes_all_values(self):
     tag = Tag('type', 'value1', 'value2', 'value3', hidden=True)
     tag.sanitize()
     assert not tag
예제 #25
0
 def test_not_present_with_no_values(self):
     tag = Tag('type')
     assert not tag.present
     assert not tag
예제 #26
0
 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
예제 #27
0
 def test_required_with_values_passes(self):
     tag = Tag('type', 'asdf', required=True)
     tag.validate()
     assert tag.valid
예제 #28
0
 def test_when_not_hidden_removes_nothing(self):
     tag = Tag('type', 'value1', 'value2', 'value3', hidden=False)
     tag.sanitize()
     assert tag.data == ['value1', 'value2', 'value3']
예제 #29
0
 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
예제 #30
0
 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']