Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 10
0
 def test_required_with_no_values_fails(self):
     tag = Tag('type', required=True)
     tag.validate()
     assert not tag.valid
Ejemplo n.º 11
0
 def test_present_with_values_set(self):
     tag = Tag('type', 'asdf')
     assert tag.present
     assert tag
Ejemplo n.º 12
0
 def test_filled_with_values_set(self):
     tag = Tag('type', 'asdf')
     assert tag.filled
     assert tag
Ejemplo n.º 13
0
def test_append_ignores_empty_values():
    tag = Tag('type')
    tag.append(' \t ')
    assert tag.filled is False
Ejemplo n.º 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
Ejemplo n.º 15
0
 def test_matches_partial_values(self):
     tag = Tag('type', 'value1', 'value2', 'value3')
     assert tag.contains('val')
Ejemplo n.º 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']
Ejemplo n.º 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
Ejemplo n.º 18
0
 def test_returns_string_if_present(self):
     tag = Tag('type', 'value1', 'value2')
     assert tag.first_value() == 'value1'
Ejemplo n.º 19
0
def test_saves_default_values():
    tag = Tag('type', 'asdf', '1234')
    assert 'asdf' in tag
    assert '1234' in tag
Ejemplo n.º 20
0
 def test_returns_none_if_no_values(self):
     tag = Tag('type')
     assert tag.first_value() is None
Ejemplo n.º 21
0
def test_filled_data_ignores_empties():
    tag = Tag('type')
    tag.append(' \t ')
    tag.append('human')
    assert tag.filled_data == ['human']
Ejemplo n.º 22
0
def test_bool_truthy_when_present():
    tag = Tag('type')
    assert not tag
    tag.append('human')
    assert tag
Ejemplo n.º 23
0
 def test_not_filled_with_no_values(self):
     tag = Tag('type')
     assert not tag.filled
     assert not tag
Ejemplo n.º 24
0
 def test_when_hidden_removes_all_values(self):
     tag = Tag('type', 'value1', 'value2', 'value3', hidden=True)
     tag.sanitize()
     assert not tag
Ejemplo n.º 25
0
 def test_not_present_with_no_values(self):
     tag = Tag('type')
     assert not tag.present
     assert not tag
Ejemplo n.º 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
Ejemplo n.º 27
0
 def test_required_with_values_passes(self):
     tag = Tag('type', 'asdf', required=True)
     tag.validate()
     assert tag.valid
Ejemplo n.º 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']
Ejemplo n.º 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
Ejemplo n.º 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']