test_sphinx.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import os.path
  2. import posixpath
  3. import tempfile
  4. import unittest
  5. import sphinx_multiversion
  6. class VersionInfoTestCase(unittest.TestCase):
  7. def setUp(self):
  8. root = tempfile.gettempdir()
  9. self.versioninfo = sphinx_multiversion.sphinx.VersionInfo(
  10. app=None,
  11. context={"pagename": "testpage"},
  12. metadata={
  13. "master": {
  14. "name": "master",
  15. "version": "",
  16. "release": "0.2",
  17. "is_released": False,
  18. "source": "heads",
  19. "creatordate": "2020-08-07 07:45:20 -0700",
  20. "basedir": os.path.join(root, "master"),
  21. "sourcedir": os.path.join(root, "master", "docs"),
  22. "outputdir": os.path.join(root, "build", "html", "master"),
  23. "confdir": os.path.join(root, "master", "docs"),
  24. "docnames": ["testpage", "appendix/faq"],
  25. },
  26. "v0.1.0": {
  27. "name": "v0.1.0",
  28. "version": "",
  29. "release": "0.1.0",
  30. "is_released": True,
  31. "source": "tags",
  32. "creatordate": "2020-07-16 08:45:20 -0100",
  33. "basedir": os.path.join(root, "v0.1.0"),
  34. "sourcedir": os.path.join(root, "v0.1.0", "docs"),
  35. "outputdir": os.path.join(root, "build", "html", "v0.1.0"),
  36. "confdir": os.path.join(root, "v0.1.0", "docs"),
  37. "docnames": ["old_testpage", "appendix/faq"],
  38. },
  39. "branch-with/slash": {
  40. "name": "branch-with/slash",
  41. "version": "",
  42. "release": "0.1.1",
  43. "is_released": False,
  44. "source": "heads",
  45. "creatordate": "2020-08-06 11:53:06 -0400",
  46. "basedir": os.path.join(root, "branch-with/slash"),
  47. "sourcedir": os.path.join(
  48. root, "branch-with/slash", "docs"
  49. ),
  50. "outputdir": os.path.join(
  51. root, "build", "html", "branch-with/slash"
  52. ),
  53. "confdir": os.path.join(root, "branch-with/slash", "docs"),
  54. "docnames": ["testpage"],
  55. },
  56. },
  57. current_version_name="master",
  58. )
  59. def test_tags_property(self):
  60. versions = self.versioninfo.tags
  61. self.assertEqual([version.name for version in versions], ["v0.1.0"])
  62. def test_branches_property(self):
  63. versions = self.versioninfo.branches
  64. self.assertEqual(
  65. [version.name for version in versions],
  66. ["master", "branch-with/slash"],
  67. )
  68. def test_releases_property(self):
  69. versions = self.versioninfo.releases
  70. self.assertEqual([version.name for version in versions], ["v0.1.0"])
  71. def test_in_development_property(self):
  72. versions = self.versioninfo.in_development
  73. self.assertEqual(
  74. [version.name for version in versions],
  75. ["master", "branch-with/slash"],
  76. )
  77. def test_vhasdoc(self):
  78. self.assertTrue(self.versioninfo.vhasdoc("master"))
  79. self.assertFalse(self.versioninfo.vhasdoc("v0.1.0"))
  80. self.assertTrue(self.versioninfo.vhasdoc("branch-with/slash"))
  81. self.versioninfo.context["pagename"] = "appendix/faq"
  82. self.assertTrue(self.versioninfo.vhasdoc("master"))
  83. self.assertTrue(self.versioninfo.vhasdoc("v0.1.0"))
  84. self.assertFalse(self.versioninfo.vhasdoc("branch-with/slash"))
  85. def test_vpathto(self):
  86. self.assertEqual(self.versioninfo.vpathto("master"), "testpage.html")
  87. self.assertEqual(
  88. self.versioninfo.vpathto("v0.1.0"),
  89. posixpath.join("..", "v0.1.0", "index.html"),
  90. )
  91. self.assertEqual(
  92. self.versioninfo.vpathto("branch-with/slash"),
  93. posixpath.join("..", "branch-with/slash", "testpage.html"),
  94. )
  95. self.versioninfo.context["pagename"] = "appendix/faq"
  96. self.assertEqual(self.versioninfo.vpathto("master"), "faq.html")
  97. self.assertEqual(
  98. self.versioninfo.vpathto("v0.1.0"),
  99. posixpath.join("..", "..", "v0.1.0", "appendix", "faq.html"),
  100. )
  101. self.assertEqual(
  102. self.versioninfo.vpathto("branch-with/slash"),
  103. posixpath.join("..", "..", "branch-with/slash", "index.html"),
  104. )