Skip to content

Commit 287c559

Browse files
musically-utvstinner
authored andcommitted
bpo-30822: Fix testing of datetime module. (#2530) (#2783)
Only C implementation was tested.
1 parent fff2a21 commit 287c559

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Lib/datetime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,8 @@ def _name_from_offset(delta):
22712271
_check_tzinfo_arg, _check_tzname, _check_utc_offset, _cmp, _cmperror,
22722272
_date_class, _days_before_month, _days_before_year, _days_in_month,
22732273
_format_time, _is_leap, _isoweek1monday, _math, _ord2ymd,
2274-
_time, _time_class, _tzinfo_class, _wrap_strftime, _ymd2ord)
2274+
_time, _time_class, _tzinfo_class, _wrap_strftime, _ymd2ord,
2275+
_divide_and_round)
22752276
# XXX Since import * above excludes names that start with _,
22762277
# docstring does not get overwritten. In the future, it may be
22772278
# appropriate to maintain a single module level docstring and

Lib/test/datetimetester.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def test_constants(self):
6161
self.assertEqual(datetime.MAXYEAR, 9999)
6262

6363
def test_name_cleanup(self):
64-
if '_Fast' not in str(self):
65-
return
64+
if '_Pure' in self.__class__.__name__:
65+
self.skipTest('Only run for Fast C implementation')
66+
6667
datetime = datetime_module
6768
names = set(name for name in dir(datetime)
6869
if not name.startswith('__') and not name.endswith('__'))
@@ -72,8 +73,9 @@ def test_name_cleanup(self):
7273
self.assertEqual(names - allowed, set([]))
7374

7475
def test_divide_and_round(self):
75-
if '_Fast' in str(self):
76-
return
76+
if '_Fast' in self.__class__.__name__:
77+
self.skipTest('Only run for Pure Python implementation')
78+
7779
dar = datetime_module._divide_and_round
7880

7981
self.assertEqual(dar(-10, -3), 3)
@@ -2851,7 +2853,7 @@ def tzname(self, dt): return self.tz
28512853
self.assertRaises(TypeError, t.strftime, "%Z")
28522854

28532855
# Issue #6697:
2854-
if '_Fast' in str(self):
2856+
if '_Fast' in self.__class__.__name__:
28552857
Badtzname.tz = '\ud800'
28562858
self.assertRaises(ValueError, t.strftime, "%Z")
28572859

Lib/test/test_datetime.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
2121
# not believe this, but in spite of all the sys.modules trickery running a _Pure
2222
# test last will leave a mix of pure and native datetime stuff lying around.
23-
test_classes = []
23+
all_test_classes = []
2424

2525
for module, suffix in zip(test_modules, test_suffixes):
2626
test_classes = []
@@ -34,7 +34,8 @@
3434
test_classes.extend(type(test) for test in suit)
3535
test_classes = sorted(set(test_classes), key=lambda cls: cls.__qualname__)
3636
for cls in test_classes:
37-
cls.__name__ = name + suffix
37+
cls.__name__ += suffix
38+
cls.__qualname__ += suffix
3839
@classmethod
3940
def setUpClass(cls_, module=module):
4041
cls_._save_sys_modules = sys.modules.copy()
@@ -47,9 +48,10 @@ def tearDownClass(cls_):
4748
sys.modules.update(cls_._save_sys_modules)
4849
cls.setUpClass = setUpClass
4950
cls.tearDownClass = tearDownClass
51+
all_test_classes.extend(test_classes)
5052

5153
def test_main():
52-
run_unittest(*test_classes)
54+
run_unittest(*all_test_classes)
5355

5456
if __name__ == "__main__":
5557
test_main()

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@ Doobee R. Tzeck
16021602
Eren Türkay
16031603
Lionel Ulmer
16041604
Adnan Umer
1605+
Utkarsh Upadhyay
16051606
Roger Upole
16061607
Daniel Urban
16071608
Michael Urman

0 commit comments

Comments
 (0)