mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-26 03:41:04 +03:00
Better API for tags in sections.
This commit is contained in:
parent
3a1f8821c1
commit
a58a237bc1
|
@ -107,7 +107,7 @@ def parse_file_to_book(inputfile, book):
|
|||
def add_section_to_book(book, name, text, number=None, tags=None):
|
||||
section = sections.Section(name, text)
|
||||
if tags:
|
||||
section.set_tags(tags)
|
||||
section.add_tags(tags)
|
||||
book.add(section)
|
||||
if number:
|
||||
book.force_section_nr(name, number)
|
||||
|
|
|
@ -7,8 +7,11 @@ class Section:
|
|||
self.text = text
|
||||
self.tags = set()
|
||||
|
||||
def set_tags(self, tags):
|
||||
self.tags = set(tags)
|
||||
def add_tags(self, tags):
|
||||
self.tags.update(set(tags))
|
||||
|
||||
def hastag(self, tag):
|
||||
return tag in self.tags
|
||||
|
||||
def __repr__(self):
|
||||
return "Section(%s, %s, %s)" % (repr(self.name), repr(self.text),
|
||||
|
|
|
@ -14,6 +14,17 @@ class TestSection(TestCase):
|
|||
self.assertEqual(sec.name, "nnn")
|
||||
self.assertEqual(sec.text, "text")
|
||||
|
||||
def test_add_tags(self):
|
||||
sec = sections.Section("nnn", "text")
|
||||
sec.add_tags(['a', 'b'])
|
||||
self.assertTrue(sec.hastag('a'))
|
||||
self.assertTrue(sec.hastag('b'))
|
||||
sec.add_tags(['c', 'd'])
|
||||
self.assertTrue(sec.hastag('a'))
|
||||
self.assertTrue(sec.hastag('b'))
|
||||
self.assertTrue(sec.hastag('c'))
|
||||
self.assertTrue(sec.hastag('d'))
|
||||
|
||||
class TestBook(TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue