Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testDates.py 1.8KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import unittest
  2. from datetime import datetime
  3. import pywintypes
  4. import win32com.client
  5. import win32com.server.util
  6. import win32com.test.util
  7. from win32timezone import TimeZoneInfo
  8. # A COM object so we can pass dates to and from the COM boundary.
  9. class Tester:
  10. _public_methods_ = ["TestDate"]
  11. def TestDate(self, d):
  12. assert isinstance(d, datetime)
  13. return d
  14. def test_ob():
  15. return win32com.client.Dispatch(win32com.server.util.wrap(Tester()))
  16. class TestCase(win32com.test.util.TestCase):
  17. def check(self, d, expected=None):
  18. if not issubclass(pywintypes.TimeType, datetime):
  19. self.skipTest("this is testing pywintypes and datetime")
  20. got = test_ob().TestDate(d)
  21. self.assertEqual(got, expected or d)
  22. def testUTC(self):
  23. self.check(
  24. datetime(
  25. year=2000,
  26. month=12,
  27. day=25,
  28. microsecond=500000,
  29. tzinfo=TimeZoneInfo.utc(),
  30. )
  31. )
  32. def testLocal(self):
  33. self.check(
  34. datetime(
  35. year=2000,
  36. month=12,
  37. day=25,
  38. microsecond=500000,
  39. tzinfo=TimeZoneInfo.local(),
  40. )
  41. )
  42. def testMSTruncated(self):
  43. # milliseconds are kept but microseconds are lost after rounding.
  44. self.check(
  45. datetime(
  46. year=2000,
  47. month=12,
  48. day=25,
  49. microsecond=500500,
  50. tzinfo=TimeZoneInfo.utc(),
  51. ),
  52. datetime(
  53. year=2000,
  54. month=12,
  55. day=25,
  56. microsecond=500000,
  57. tzinfo=TimeZoneInfo.utc(),
  58. ),
  59. )
  60. if __name__ == "__main__":
  61. unittest.main()