test_parsing.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. from pathlib import Path
  2. from gemini_antenna.multiFeedParsing import (parsegemsub, parsetwtxt, parsexml,
  3. FeedEntry, TwtxtEntry)
  4. def test_gemsub():
  5. with open(Path("tests") / "feed.gmi") as file:
  6. feed = file.read()
  7. entries = parsegemsub(feed, "gemini://gemini.jrandom.net/gemlog/")
  8. assert entries == [
  9. FeedEntry(
  10. feedurl="gemini://gemini.jrandom.net/gemlog/",
  11. author="J. Random Geminaut's gemlog",
  12. updated=1605855600,
  13. title="- Early Bokashi composting experiments",
  14. link="gemini://gemini.jrandom.net/gemlog/bokashi.gmi"
  15. ),
  16. FeedEntry(
  17. feedurl="gemini://gemini.jrandom.net/gemlog/",
  18. author="J. Random Geminaut's gemlog",
  19. updated=1605250800,
  20. title="- Trying to get to grips with finite simple groups...",
  21. link="gemini://gemini.jrandom.net/gemlog/finite-simple-groups.gmi"
  22. ),
  23. FeedEntry(
  24. feedurl="gemini://gemini.jrandom.net/gemlog/",
  25. author="J. Random Geminaut's gemlog",
  26. updated=1604646000,
  27. title="- I started a balcony garden!",
  28. link="gemini://gemini.jrandom.net/gemlog/balcony.gmi"
  29. )
  30. ]
  31. def test_atom():
  32. with open(Path("tests") / "feed.atom") as file:
  33. feed = file.read()
  34. entries = parsexml(feed, "gemini://gemini.jrandom.net/gemlog/")
  35. assert entries == [
  36. FeedEntry(
  37. feedurl="gemini://gemini.jrandom.net/gemlog/",
  38. author="J. Random Geminaut's gemlog",
  39. updated=1605855600,
  40. title="Early Bokashi composting experiments",
  41. link="gemini://gemini.jrandom.net/gemlog/bokashi.gmi"
  42. ),
  43. FeedEntry(
  44. feedurl="gemini://gemini.jrandom.net/gemlog/",
  45. author="J. Random Geminaut's gemlog",
  46. updated=1605250800,
  47. title="Trying to get to grips with finite simple groups...",
  48. link="gemini://gemini.jrandom.net/gemlog/finite-simple-groups.gmi"
  49. ),
  50. FeedEntry(
  51. feedurl="gemini://gemini.jrandom.net/gemlog/",
  52. author="J. Random Geminaut's gemlog",
  53. updated=1604646000,
  54. title="I started a balcony garden!",
  55. link="gemini://gemini.jrandom.net/gemlog/balcony.gmi"
  56. )
  57. ]
  58. def test_twtxt():
  59. with open(Path("tests") / "twtxt.txt") as file:
  60. feed = file.read()
  61. entries = parsetwtxt(feed, "gemini://example.com/twtxt.txt")
  62. assert entries == [
  63. TwtxtEntry(
  64. feedurl="gemini://example.com/twtxt.txt",
  65. author="gemini://example.com/twtxt.txt",
  66. posted=1454589000.0,
  67. twt="You can really go crazy here! ┐(゚∀゚)┌"
  68. ),
  69. TwtxtEntry(
  70. feedurl="gemini://example.com/twtxt.txt",
  71. author="gemini://example.com/twtxt.txt",
  72. posted=1454537100.0,
  73. twt="@<example http://example.org/twtxt.txt> welcome to twtxt!"
  74. ),
  75. TwtxtEntry(
  76. feedurl="gemini://example.com/twtxt.txt",
  77. author="gemini://example.com/twtxt.txt",
  78. posted=1454320800.0,
  79. twt="This is just another example."
  80. ),
  81. TwtxtEntry(
  82. feedurl="gemini://example.com/twtxt.txt",
  83. author="gemini://example.com/twtxt.txt",
  84. posted=1449918000.0,
  85. twt="Fiat lux!"
  86. )
  87. ]