test_package.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from collections import namedtuple
  2. import json
  3. import os
  4. import unittest
  5. from yarg.package import json2package
  6. class TestPackage(unittest.TestCase):
  7. def setUp(self):
  8. package = os.path.join(os.path.dirname(__file__),
  9. 'package.json')
  10. self.json = json.loads(open(package).read())
  11. self.package = json2package(open(package).read())
  12. def test_repr(self):
  13. self.assertEquals(u'<Package yarg>', self.package.__repr__())
  14. def test_name(self):
  15. self.assertEquals(u'yarg', self.package.name)
  16. def test_pypi_url(self):
  17. self.assertEquals(u'http://pypi.python.org/pypi/yarg',
  18. self.package.pypi_url)
  19. def test_summary(self):
  20. self.assertEquals(u'This is the short summary.', self.package.summary)
  21. def test_description(self):
  22. self.assertEquals(u'This is the long description.',
  23. self.package.description)
  24. def test_homepage(self):
  25. self.assertEquals(u'https://kura.io/yarg/',
  26. self.package.homepage)
  27. def test_bugtracker(self):
  28. self.assertEquals(u'https://github.com/kura/yarg/issues',
  29. self.package.bugtracker)
  30. def test_docs(self):
  31. self.assertEquals(u'http://yarg.readthedocs.org/',
  32. self.package.docs)
  33. def test_author(self):
  34. author = namedtuple('Author', 'name email')
  35. self.assertEquals(author(name='Kura', email='kura@kura.io'),
  36. self.package.author)
  37. def test_maintainer(self):
  38. maintainer = namedtuple('Maintainer', 'name email')
  39. self.assertEquals(maintainer(name='Kura', email='kura@kura.io'),
  40. self.package.maintainer)
  41. def test_license(self):
  42. self.assertEquals(u'MIT',
  43. self.package.license)
  44. def test_license_from_classifiers(self):
  45. self.assertEquals(u'MIT License',
  46. self.package.license_from_classifiers)
  47. def test_downloads(self):
  48. downloads = namedtuple('Downloads', 'day week month')
  49. self.assertEquals(downloads(day=34001, week=72700, month=510000),
  50. self.package.downloads)
  51. def test_classifiers(self):
  52. self.assertEquals([u'Development Status :: 5 - Production/Stable',
  53. u'Intended Audience :: Developers',
  54. u'License :: OSI Approved :: MIT License',
  55. u'Programming Language :: Python',
  56. u'Programming Language :: Python :: 2.6',
  57. u'Programming Language :: Python :: 2.7',
  58. u'Programming Language :: Python :: 3',
  59. u'Programming Language :: Python :: 3.1',
  60. u'Programming Language :: Python :: 3.2',
  61. u'Programming Language :: Python :: 3.3',
  62. u'Programming Language :: Python :: Implementation :: CPython',
  63. u'Programming Language :: Python :: Implementation :: PyPy'],
  64. self.package.classifiers)
  65. def test_release_ids(self):
  66. self.assertEquals([u'0.0.0', u'0.0.2', u'0.0.15'],
  67. self.package.release_ids)
  68. def test_latest_release_id(self):
  69. self.assertEquals(u'0.0.15', self.package.latest_release_id)
  70. def test_has_wheel(self):
  71. self.assertEquals(True, self.package.has_wheel)
  72. def test_has_egg(self):
  73. self.assertEquals(False, self.package.has_egg)
  74. def test_has_source(self):
  75. self.assertEquals(True, self.package.has_source)
  76. def test_python_versions(self):
  77. self.assertEquals([u'2.6', u'2.7', u'3.1', u'3.2', u'3.3'],
  78. self.package.python_versions)
  79. def test_python_implementations(self):
  80. self.assertEquals([u'CPython', u'PyPy'],
  81. self.package.python_implementations)
  82. class TestPackageMissingData(unittest.TestCase):
  83. def setUp(self):
  84. package = os.path.join(os.path.dirname(__file__),
  85. 'package_no_homepage_bugtrack_one_release.json')
  86. self.json = json.loads(open(package).read())
  87. self.package = json2package(open(package).read())
  88. def test_homepage(self):
  89. self.assertEquals(None, self.package.homepage)
  90. def test_bugtracker(self):
  91. self.assertEquals(None, self.package.bugtracker)
  92. def test_docs(self):
  93. self.assertEquals(None, self.package.docs)
  94. def test_latest_release_id(self):
  95. self.assertEquals(u'0.0.0', self.package.latest_release_id)
  96. def test_has_wheel(self):
  97. self.assertEquals(False, self.package.has_wheel)
  98. def test_has_egg(self):
  99. self.assertEquals(True, self.package.has_egg)
  100. def test_has_source(self):
  101. self.assertEquals(False, self.package.has_source)