Commits

German Larrain  committed 06ac537

tests.utils: added module 'test_version', including a test case for
'utils.version.get_version'.

  • Participants
  • Parent commits c4c1e74

Comments (0)

Files changed (1)

File tests/utils/test_version.py

+from unittest import TestCase
+
+import mock
+
+from ars.utils.version import get_version
+
+
+class VersionTest(TestCase):
+
+	def setUp(self):
+		self.hg_tip_timestamp = '20130401011455'
+
+	def test_get_version(self):
+		self._helper('0.4.dev%s', version=(0, 4, 0, 'alpha', 0))
+		self._helper('0.4a1', version=(0, 4, 0, 'alpha', 1))
+
+		self._helper('0.4.1.dev%s', version=(0, 4, 1, 'alpha', 0))
+		self._helper('0.4.1a1', version=(0, 4, 1, 'alpha', 1))
+		self._helper('0.4b0', version=(0, 4, 0, 'beta', 0))
+		self._helper('0.4c0', version=(0, 4, 0, 'rc', 0))
+		self._helper('0.4', version=(0, 4, 0, 'final', 0))
+		self._helper('0.4', version=(0, 4, 0, 'final', 1))
+		self._helper('0.4.1', version=(0, 4, 1, 'final', 0))
+		self._helper('0.4.dev', version=(0, 4, 0, 'alpha', 0), length='medium')
+		self._helper('0.4', version=(0, 4, 0, 'alpha', 0), length='short')
+
+	def _helper(self, expected, version=None, length='full'):
+		try:
+			expected %= self.hg_tip_timestamp
+		except TypeError:
+			pass
+
+		with mock.patch('ars.utils.version.get_hg_tip_timestamp') as mock_get:
+			mock_get.return_value = self.hg_tip_timestamp
+			self.assertEqual(
+				expected,
+				get_version(version=version, length=length))