aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Kaplan-Moss2009-04-28 09:44:10 -0500
committerJacob Kaplan-Moss2009-04-28 09:44:10 -0500
commit3a16e5d48ce6125fd9e5fc6573ffb80bd540c697 (patch)
treedeb8af78788ec7a18eca3d53c6ac4649756d8008
parent8d062183fe97300fbc6583c3f0e21d340febd84b (diff)
downloaddjango-shorturls-3a16e5d48ce6125fd9e5fc6573ffb80bd540c697.tar.bz2
Moved the baseconv tests into the test suite so they'll be run along with everythign else.
-rw-r--r--src/shorturls/baseconv.py9
-rw-r--r--src/shorturls/tests/__init__.py3
-rw-r--r--src/shorturls/tests/test_baseconv.py19
3 files changed, 22 insertions, 9 deletions
diff --git a/src/shorturls/baseconv.py b/src/shorturls/baseconv.py
index 1b7efbd..ba2f759 100644
--- a/src/shorturls/baseconv.py
+++ b/src/shorturls/baseconv.py
@@ -55,11 +55,4 @@ bin = BaseConverter('01')
hexconv = BaseConverter('0123456789ABCDEF')
base62 = BaseConverter(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
-)
-
-if __name__ == '__main__':
- nums = [-10 ** 10, 10 ** 10] + range(-100, 100)
- for c in [bin, hexconv, base62]:
- for i in nums:
- assert i == c.to_decimal(c.from_decimal(i)), '%s failed' % i
-
+) \ No newline at end of file
diff --git a/src/shorturls/tests/__init__.py b/src/shorturls/tests/__init__.py
index 25d0b61..6687828 100644
--- a/src/shorturls/tests/__init__.py
+++ b/src/shorturls/tests/__init__.py
@@ -1,3 +1,4 @@
from shorturls.tests.models import *
from shorturls.tests.test_views import *
-from shorturls.tests.test_templatetag import * \ No newline at end of file
+from shorturls.tests.test_templatetag import *
+from shorturls.tests.test_baseconv import * \ No newline at end of file
diff --git a/src/shorturls/tests/test_baseconv.py b/src/shorturls/tests/test_baseconv.py
new file mode 100644
index 0000000..5e203b7
--- /dev/null
+++ b/src/shorturls/tests/test_baseconv.py
@@ -0,0 +1,19 @@
+import unittest
+from shorturls import baseconv
+
+class BaseConvTests(unittest.TestCase):
+
+ def _test_converter(self, converter):
+ nums = [-10 ** 10, 10 ** 10] + range(-100, 100)
+ for before in nums:
+ after = converter.to_decimal(converter.from_decimal(before))
+ self.assertEqual(before, after)
+
+ def test_bin(self):
+ self._test_converter(baseconv.bin)
+
+ def test_hex(self):
+ self._test_converter(baseconv.hexconv)
+
+ def test_base62(self):
+ self._test_converter(baseconv.base62) \ No newline at end of file