Commit b42f338f authored by Lysander Trischler's avatar Lysander Trischler
Browse files

Simplify tests even further

parent 28e23209
......@@ -2,7 +2,7 @@
import datetime
import unittest
from libgotwtxt import Link, parse_file, Subject, Twt, Twter
from libgotwtxt import Link, parse_file, Subject, Twt, Twter, TwtFile
UTC_PLUS_2 = datetime.timezone(datetime.timedelta(hours=2))
TWTER = Twter(nick="hugo",
......@@ -13,98 +13,81 @@ TWTER = Twter(nick="hugo",
class ParseFileTest(unittest.TestCase):
def test_single_line(self):
twtfile = parse_file("2021-08-02T10:27:42+02:00\tHello world.", TWTER)
self.assertIsNotNone(twtfile, "parse_file returned None")
self.assertEqual(TWTER, twtfile.twter, "twter of twt file does not match")
self.assertEqual(1, len(twtfile.twts), "number of twts does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 2, 10, 27, 42, tzinfo=UTC_PLUS_2),
hash="slrnx6a",
subject=Subject(text="#slrnx6a", tag=Link(text="slrnx6a", target=None)),
mentions=[],
links=[]),
twtfile.twts[0])
self.assertEqual(TwtFile(twter=TWTER, twts=[
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 2, 10, 27, 42, tzinfo=UTC_PLUS_2),
hash="slrnx6a",
subject=Subject(text="#slrnx6a", tag=Link(text="slrnx6a", target=None)),
mentions=[],
links=[])]), twtfile)
def test_two_lines(self):
twtfile = parse_file(
"2021-08-02T10:27:42+02:00\tHello world.\n"
"2021-08-03T09:28:45+02:00\tFoo bar eggs and spam.\n",
TWTER)
self.assertIsNotNone(twtfile, "parse_file returned None")
self.assertEqual(TWTER, twtfile.twter, "twter of twt file does not match")
self.assertEqual(2, len(twtfile.twts), "number of twts does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 2, 10, 27, 42, tzinfo=UTC_PLUS_2),
hash="slrnx6a",
subject=Subject(text="#slrnx6a", tag=Link(text="slrnx6a", target=None)),
mentions=[],
links=[]),
twtfile.twts[0], "first twt does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 9, 28, 45, tzinfo=UTC_PLUS_2),
hash="zm7fnka",
subject=Subject(text="#zm7fnka", tag=Link(text="zm7fnka", target=None)),
mentions=[],
links=[]),
twtfile.twts[1], "second twt does not match")
self.assertEqual(TwtFile(twter=TWTER, twts=[
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 2, 10, 27, 42, tzinfo=UTC_PLUS_2),
hash="slrnx6a",
subject=Subject(text="#slrnx6a", tag=Link(text="slrnx6a", target=None)),
mentions=[],
links=[]),
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 9, 28, 45, tzinfo=UTC_PLUS_2),
hash="zm7fnka",
subject=Subject(text="#zm7fnka", tag=Link(text="zm7fnka", target=None)),
mentions=[],
links=[])]), twtfile)
def test_markdown_links(self):
twtfile = parse_file(
"2021-08-03T11:16:13+02:00\tHello [wonderful](https://example.com/) "
"and [nice](https://example.com/test) world!",
TWTER)
self.assertIsNotNone(twtfile, "parse_file returned None")
self.assertEqual(TWTER, twtfile.twter, "twter of twt file does not match")
self.assertEqual(1, len(twtfile.twts), "number of twts does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 11, 16, 13, tzinfo=UTC_PLUS_2),
hash="zv6vujq",
subject=Subject(text="#zv6vujq", tag=Link(text="zv6vujq", target=None)),
mentions=[],
links=[Link(text="wonderful", target="https://example.com/"),
Link(text="nice", target="https://example.com/test")]),
twtfile.twts[0])
self.assertEqual(TwtFile(twter=TWTER, twts=[
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 11, 16, 13, tzinfo=UTC_PLUS_2),
hash="zv6vujq",
subject=Subject(text="#zv6vujq", tag=Link(text="zv6vujq", target=None)),
mentions=[],
links=[Link(text="wonderful", target="https://example.com/"),
Link(text="nice", target="https://example.com/test")])]), twtfile)
def test_subjects(self):
twtfile = parse_file(
"2021-08-03T12:28:26+02:00\t(#<1234567 https://example.com/1234567>) I agree!\n"
"2021-08-03T12:33:17+02:00\t(re: foo) Well, it's quite complicated.\n",
TWTER)
self.assertIsNotNone(twtfile, "parse_file returned None")
self.assertEqual(TWTER, twtfile.twter, "twter of twt file does not match")
self.assertEqual(2, len(twtfile.twts), "number of twts does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 12, 28, 26, tzinfo=UTC_PLUS_2),
hash="g2xdgsq",
subject=Subject(text="#<1234567 https://example.com/1234567>",
tag=Link(text="1234567", target="https://example.com/1234567")),
mentions=[],
links=[]),
twtfile.twts[0], "first twt does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 12, 33, 17, tzinfo=UTC_PLUS_2),
hash="wqw7ipq",
subject=Subject(text="re: foo", tag=None),
mentions=[],
links=[]),
twtfile.twts[1], "second twt does not match")
self.assertEqual(TwtFile(twter=TWTER, twts=[
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 12, 28, 26, tzinfo=UTC_PLUS_2),
hash="g2xdgsq",
subject=Subject(text="#<1234567 https://example.com/1234567>",
tag=Link(text="1234567", target="https://example.com/1234567")),
mentions=[],
links=[]),
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 12, 33, 17, tzinfo=UTC_PLUS_2),
hash="wqw7ipq",
subject=Subject(text="re: foo", tag=None),
mentions=[],
links=[])]), twtfile)
def test_mentions(self):
twtfile = parse_file(
"2021-08-03T15:04:09+02:00\tHello @<eugen https://example.org/~eugen/twtxt.txt>!",
TWTER)
self.assertIsNotNone(twtfile, "parse_file returned None")
self.assertEqual(TWTER, twtfile.twter, "twter of twt file does not match")
self.assertEqual(1, len(twtfile.twts), "number of twts does not match")
self.assertEqual(Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 15, 4, 9, tzinfo=UTC_PLUS_2),
hash="vu5np6q",
subject=Subject(text="#vu5np6q", tag=Link(text="vu5np6q", target=None)),
mentions=[Twter(nick="eugen",
url="https://example.org/~eugen/twtxt.txt",
avatar="",
tagline="")],
links=[]),
twtfile.twts[0])
self.assertEqual(TwtFile(twter=TWTER, twts=[
Twt(twter=TWTER,
created=datetime.datetime(2021, 8, 3, 15, 4, 9, tzinfo=UTC_PLUS_2),
hash="vu5np6q",
subject=Subject(text="#vu5np6q", tag=Link(text="vu5np6q", target=None)),
mentions=[Twter(nick="eugen",
url="https://example.org/~eugen/twtxt.txt",
avatar="",
tagline="")],
links=[])]), twtfile)
if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment