修改前后 diff
--- a/app.py
+++ b/app.py
@@ -1,2 +1,4 @@
+from datetime import datetime
+
def ordered(rows):
- return sorted(rows, key=lambda x: x['date'])
+ return sorted(rows, key=lambda x: datetime.strptime(x['date'], '%d/%m/%Y'))
真实测试记录
before exit=1\ntest_contract (test_app.LessonTest.test_contract) ... FAIL
======================================================================
FAIL: test_contract (test_app.LessonTest.test_contract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/lorin/my-clone/quickrout/public/downloads/tutorials-batch50b-20261014/practical/opencode-date-sort-minimal-diff/before/test_app.py", line 7, in test_contract
self.assertEqual([r['id'] for r in ordered(rows)], ['B','A'])
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Lists differ: ['A', 'B'] != ['B', 'A']
First differing element 0:
'A'
'B'
- ['A', 'B']
+ ['B', 'A']
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
\nfixed exit=0\ntest_contract (test_app.LessonTest.test_contract) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
标准库测试真实运行;参考代码人工编写,未执行 OpenCode 或付费模型。