summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2012-05-21 18:43:09 +0200
committerDidier Raboud <odyx@debian.org>2012-05-21 18:43:14 +0200
commit2c2abf9329f28922a50612d2c12d243e89e68aea (patch)
treef1463e3a62655b011d2d8716758239ead2d44e1b /test
parentac03eb668ff769e2ef9cf792f5000e9dc753042c (diff)
PyUT: Add rnd_string function for the creation of random strings.
Git-Dch: None
Diffstat (limited to 'test')
-rw-r--r--test/test_lsb_release.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/test/test_lsb_release.py b/test/test_lsb_release.py
index 9c5f2c2..f174b6c 100644
--- a/test/test_lsb_release.py
+++ b/test/test_lsb_release.py
@@ -6,6 +6,9 @@ import lsb_release as lr
import random
import string
+def rnd_string(min_l,max_l):
+ return ''.join( [random.choice(string.letters) for i in xrange(random.randint(min_l,max_l))])
+
class TestLSBRelease(unittest.TestCase):
def test_lookup_codename(self):
@@ -13,7 +16,7 @@ class TestLSBRelease(unittest.TestCase):
for rno in lr.RELEASE_CODENAME_LOOKUP:
cdn = lr.RELEASE_CODENAME_LOOKUP[rno]
# Test that 1.1, 1.1r0 and 1.1.8 lead to buzz. Default is picked randomly and is not supposed to go trough
- badDefault = ''.join( [random.choice(string.letters) for i in xrange(random.randint(0,9))])
+ badDefault = rnd_string(0,9)
self.assertEqual(lr.lookup_codename(rno,badDefault),cdn,'Release name `' + rno + '` is not recognized.')
self.assertEqual(lr.lookup_codename(rno + 'r' + str(random.randint(0,9)),badDefault),cdn,'Release name `' + rno + 'r*` is not recognized.')
self.assertEqual(lr.lookup_codename(rno + '.' + str(random.randint(0,9)),badDefault),cdn,'Release name `' + rno + '.*` is not recognized.')
@@ -67,7 +70,7 @@ class TestLSBRelease(unittest.TestCase):
random.shuffle(shortnames)
longnames = {}
for shortname in shortnames:
- longnames[lr.longnames[shortname]] = ''.join( [random.choice(string.letters) for i in xrange(random.randint(1,9))])
+ longnames[lr.longnames[shortname]] = rnd_string(1,9)
release_line += shortname + '=' + longnames[lr.longnames[shortname]] + ','
release_line = string.strip(release_line,',')
self.assertEqual(sorted(lr.parse_policy_line(release_line)),sorted(longnames),'parse_policy_line(' + release_line + ')')