[devtools/fill] fix date generation and its test stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Mon, 22 Feb 2010 19:25:04 +0100
branchstable
changeset 4651 f9cd35dece09
parent 4650 965395d821bc
child 4652 7c41eea7fc30
[devtools/fill] fix date generation and its test
devtools/fill.py
devtools/test/unittest_dbfill.py
--- a/devtools/fill.py	Mon Feb 22 18:22:54 2010 +0100
+++ b/devtools/fill.py	Mon Feb 22 19:25:04 2010 +0100
@@ -142,7 +142,7 @@
 
     def generate_date(self, entity, attrname, index):
         """generates a random date (format is 'yyyy-mm-dd')"""
-        base = date(randint(2000, 2004), randint(1, 12), randint(1, 28))
+        base = date(randint(2000, 2010), 1, 1) + timedelta(randint(1, 365))
         return self._constrained_generate(entity, attrname, base, timedelta(days=1), index)
 
     def generate_time(self, entity, attrname, index):
--- a/devtools/test/unittest_dbfill.py	Mon Feb 22 18:22:54 2010 +0100
+++ b/devtools/test/unittest_dbfill.py	Mon Feb 22 19:25:04 2010 +0100
@@ -9,6 +9,7 @@
 
 import os.path as osp
 import re
+import datetime
 
 from logilab.common.testlib import TestCase, unittest_main
 
@@ -41,7 +42,6 @@
     def _available_Person_firstname(self, etype, attrname):
         return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))]
 
-
     def setUp(self):
         config = ApptestConfiguration('data')
         config.bootstrap_cubes()
@@ -52,17 +52,6 @@
         self.bug_valgen = MyValueGenerator(e_schema)
         self.config = config
 
-    def _check_date(self, date):
-        """checks that 'date' is well-formed"""
-        year = date.year
-        month = date.month
-        day = date.day
-        self.failUnless(day in range(1, 29), '%s not in [0;28]' % day)
-        self.failUnless(month in range(1, 13), '%s not in [1;12]' % month)
-        self.failUnless(year in range(2000, 2005),
-                        '%s not in [2000;2004]' % year)
-
-
     def test_string(self):
         """test string generation"""
         surname = self.person_valgen.generate_attribute_value({}, 'surname', 12)
@@ -92,15 +81,14 @@
     def test_date(self):
         """test date generation"""
         # Test for random index
-        for index in range(5):
+        for index in range(10):
             date_value = self.person_valgen.generate_attribute_value({}, 'birthday', index)
-            self._check_date(date_value)
+            self.failUnless(isinstance(date_value, datetime.date))
 
     def test_phone(self):
         """tests make_tel utility"""
         self.assertEquals(make_tel(22030405), '22 03 04 05')
 
-
     def test_customized_generation(self):
         self.assertEquals(self.bug_valgen.generate_attribute_value({}, 'severity', 12),
                           u'dangerous')
@@ -110,7 +98,6 @@
                           u'yo')
 
 
-
 class ConstraintInsertionTC(TestCase):
 
     def test_writeme(self):