Skip to content

Commit c8371e6

Browse files
authored
Fix test_time (#1089)
* Fix test_time * Also fix test_nntplib
1 parent 4566729 commit c8371e6

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Src/IronPython.Modules/_datetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ public override string strftime(CodeContext/*!*/ context, string dateFormat) {
11131113

11141114
public static datetime strptime(CodeContext/*!*/ context, string date_string, string format) {
11151115
var packed = PythonTime._strptime(context, date_string, format);
1116-
return new datetime((DateTime)packed[0]);
1116+
return new datetime(packed.Item1);
11171117
}
11181118

11191119
#region IRichComparable Members

Src/IronPython.Modules/time.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ public static object strptime(CodeContext/*!*/ context, string @string) {
181181

182182
public static object strptime(CodeContext/*!*/ context, string @string, string format) {
183183
var packed = _strptime(context, @string, format);
184-
return GetDateTimeTuple((DateTime)packed[0], (DayOfWeek?)packed[1]);
184+
return GetDateTimeTuple(packed.Item1, packed.Item2);
185185
}
186186

187187
// returns object array containing 2 elements: DateTime and DayOfWeek
188-
internal static object[] _strptime(CodeContext/*!*/ context, string @string, string format) {
188+
internal static Tuple<DateTime, DayOfWeek?> _strptime(CodeContext/*!*/ context, string @string, string format) {
189189
bool postProc;
190190
FoundDateComponents foundDateComp;
191191
List<FormatInfo> formatInfo = PythonFormatToCLIFormat(format, true, out postProc, out foundDateComp);
@@ -255,7 +255,7 @@ internal static object[] _strptime(CodeContext/*!*/ context, string @string, str
255255
res = new DateTime(1900, res.Month, res.Day, res.Hour, res.Minute, res.Second, res.Millisecond, res.Kind);
256256
}
257257

258-
return new object[] { res, dayOfWeek };
258+
return Tuple.Create(res, dayOfWeek);
259259
}
260260

261261
private static string[] ExpandMicrosecondFormat(int fIdx, string [] formatParts) {

Src/StdLib/Lib/test/test_nntplib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _check_desc(desc):
6969
desc = self.server.description(self.GROUP_NAME)
7070
_check_desc(desc)
7171
# Another sanity check
72-
self.assertIn("Python", desc)
72+
self.assertIn(self.DESC, desc)
7373
# With a pattern
7474
desc = self.server.description(self.GROUP_PAT)
7575
_check_desc(desc)
@@ -289,6 +289,7 @@ class NetworkedNNTPTests(NetworkedNNTPTestsMixin, unittest.TestCase):
289289
NNTP_HOST = 'news.trigofacile.com'
290290
GROUP_NAME = 'fr.comp.lang.python'
291291
GROUP_PAT = 'fr.comp.lang.*'
292+
DESC = 'Python'
292293

293294
NNTP_CLASS = NNTP
294295

@@ -311,8 +312,11 @@ class NetworkedNNTP_SSLTests(NetworkedNNTPTests):
311312
# 400 connections per day are accepted from each IP address."
312313

313314
NNTP_HOST = 'nntp.aioe.org'
314-
GROUP_NAME = 'comp.lang.python'
315-
GROUP_PAT = 'comp.lang.*'
315+
# bpo-42794: aioe.test is one of the official groups on this server
316+
# used for testing: https://news.aioe.org/manual/aioe-hierarchy/
317+
GROUP_NAME = 'aioe.test'
318+
GROUP_PAT = 'aioe.*'
319+
DESC = 'test'
316320

317321
NNTP_CLASS = getattr(nntplib, 'NNTP_SSL', None)
318322

Tests/modules/system_related/test_time.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ def test_strptime(self):
8080

8181
if is_cli: # https://github.com/IronLanguages/main/issues/239
8282
# TODO: day of the week does not work as expected
83-
with self.assertRaises(ValueError):
84-
time.strptime('Fri, July 9 7:30 PM', '%a, %B %d %I:%M %p')
83+
import System.DateTime
84+
if System.DateTime(System.DateTime.Now.Year, 7, 9).DayOfWeek == System.DayOfWeek.Friday:
85+
self.assertEqual((1900, 7, 9, 19, 30, 0, 4, 190, -1), time.strptime('Fri, July 9 7:30 PM', '%a, %B %d %I:%M %p'))
86+
else:
87+
with self.assertRaises(ValueError):
88+
time.strptime('Fri, July 9 7:30 PM', '%a, %B %d %I:%M %p')
8589
else:
8690
self.assertEqual((1900, 7, 9, 19, 30, 0, 4, 190, -1), time.strptime('Fri, July 9 7:30 PM', '%a, %B %d %I:%M %p'))
8791

0 commit comments

Comments
 (0)