added testcases for Tag and TagLine classes
This commit is contained in:
parent
659ed2dac5
commit
87fc0fe075
@ -7,6 +7,7 @@ from chatmastermind.main import create_parser, ask_cmd
|
||||
from chatmastermind.api_client import ai
|
||||
from chatmastermind.configuration import Config
|
||||
from chatmastermind.storage import create_chat_hist, save_answers, dump_data
|
||||
from chatmastermind.tags import Tag, TagLine, TagError
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, MagicMock, Mock, ANY
|
||||
|
||||
@ -231,3 +232,63 @@ class TestCreateParser(CmmTestCase):
|
||||
mock_cmdparser.add_parser.assert_any_call('config', help=ANY, aliases=ANY)
|
||||
mock_cmdparser.add_parser.assert_any_call('print', help=ANY, aliases=ANY)
|
||||
self.assertTrue('.config.yaml' in parser.get_default('config'))
|
||||
|
||||
|
||||
class TestTag(CmmTestCase):
|
||||
def test_valid_tag(self) -> None:
|
||||
tag = Tag('mytag')
|
||||
self.assertEqual(tag, 'mytag')
|
||||
|
||||
def test_invalid_tag(self) -> None:
|
||||
with self.assertRaises(TypeError):
|
||||
Tag('tag with space')
|
||||
|
||||
def test_default_separator(self) -> None:
|
||||
self.assertEqual(Tag.default_separator, ' ')
|
||||
|
||||
def test_alternative_separators(self) -> None:
|
||||
self.assertEqual(Tag.alternative_separators, [','])
|
||||
|
||||
|
||||
class TestTagLine(CmmTestCase):
|
||||
def test_valid_tagline(self) -> None:
|
||||
tagline = TagLine('TAGS: tag1 tag2')
|
||||
self.assertEqual(tagline, 'TAGS: tag1 tag2')
|
||||
|
||||
def test_invalid_tagline(self) -> None:
|
||||
with self.assertRaises(TagError):
|
||||
TagLine('tag1 tag2')
|
||||
|
||||
def test_prefix(self) -> None:
|
||||
self.assertEqual(TagLine.prefix, 'TAGS:')
|
||||
|
||||
def test_from_set(self) -> None:
|
||||
tags = {Tag('tag1'), Tag('tag2')}
|
||||
tagline = TagLine.from_set(tags)
|
||||
self.assertEqual(tagline, 'TAGS: tag1 tag2')
|
||||
|
||||
def test_tags(self) -> None:
|
||||
tagline = TagLine('TAGS: tag1 tag2')
|
||||
tags = tagline.tags()
|
||||
self.assertEqual(tags, {Tag('tag1'), Tag('tag2')})
|
||||
|
||||
def test_merge(self) -> None:
|
||||
tagline1 = TagLine('TAGS: tag1 tag2')
|
||||
tagline2 = TagLine('TAGS: tag2 tag3')
|
||||
merged_tagline = tagline1.merge({tagline2})
|
||||
self.assertEqual(merged_tagline, 'TAGS: tag1 tag2 tag3')
|
||||
|
||||
def test_delete_tags(self) -> None:
|
||||
tagline = TagLine('TAGS: tag1 tag2 tag3')
|
||||
new_tagline = tagline.delete_tags({Tag('tag1'), Tag('tag3')})
|
||||
self.assertEqual(new_tagline, 'TAGS: tag2')
|
||||
|
||||
def test_add_tags(self) -> None:
|
||||
tagline = TagLine('TAGS: tag1')
|
||||
new_tagline = tagline.add_tags({Tag('tag2'), Tag('tag3')})
|
||||
self.assertEqual(new_tagline, 'TAGS: tag1 tag2 tag3')
|
||||
|
||||
def test_rename_tags(self) -> None:
|
||||
tagline = TagLine('TAGS: old1 old2')
|
||||
new_tagline = tagline.rename_tags({(Tag('old1'), Tag('new1')), (Tag('old2'), Tag('new2'))})
|
||||
self.assertEqual(new_tagline, 'TAGS: new1 new2')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user