test_internals.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for implementation details, not necessarily part of the user-facing
  4. API.
  5. The motivating case for these tests is #483, where we want to smoke-test
  6. code that may be difficult to reach through the standard API calls.
  7. """
  8. import sys
  9. import pytest
  10. from dateutil.parser._parser import _ymd
  11. from dateutil import tz
  12. IS_PY32 = sys.version_info[0:2] == (3, 2)
  13. @pytest.mark.smoke
  14. def test_YMD_could_be_day():
  15. ymd = _ymd('foo bar 124 baz')
  16. ymd.append(2, 'M')
  17. assert ymd.has_month
  18. assert not ymd.has_year
  19. assert ymd.could_be_day(4)
  20. assert not ymd.could_be_day(-6)
  21. assert not ymd.could_be_day(32)
  22. # Assumes leap year
  23. assert ymd.could_be_day(29)
  24. ymd.append(1999)
  25. assert ymd.has_year
  26. assert not ymd.could_be_day(29)
  27. ymd.append(16, 'D')
  28. assert ymd.has_day
  29. assert not ymd.could_be_day(1)
  30. ymd = _ymd('foo bar 124 baz')
  31. ymd.append(1999)
  32. assert ymd.could_be_day(31)
  33. ###
  34. # Test that private interfaces in _parser are deprecated properly
  35. @pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
  36. def test_parser_private_warns():
  37. from dateutil.parser import _timelex, _tzparser
  38. from dateutil.parser import _parsetz
  39. with pytest.warns(DeprecationWarning):
  40. _tzparser()
  41. with pytest.warns(DeprecationWarning):
  42. _timelex('2014-03-03')
  43. with pytest.warns(DeprecationWarning):
  44. _parsetz('+05:00')
  45. @pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
  46. def test_parser_parser_private_not_warns():
  47. from dateutil.parser._parser import _timelex, _tzparser
  48. from dateutil.parser._parser import _parsetz
  49. with pytest.warns(None) as recorder:
  50. _tzparser()
  51. assert len(recorder) == 0
  52. with pytest.warns(None) as recorder:
  53. _timelex('2014-03-03')
  54. assert len(recorder) == 0
  55. with pytest.warns(None) as recorder:
  56. _parsetz('+05:00')
  57. assert len(recorder) == 0
  58. @pytest.mark.tzstr
  59. def test_tzstr_internal_timedeltas():
  60. with pytest.warns(tz.DeprecatedTzFormatWarning):
  61. tz1 = tz.tzstr("EST5EDT,5,4,0,7200,11,-3,0,7200")
  62. with pytest.warns(tz.DeprecatedTzFormatWarning):
  63. tz2 = tz.tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200")
  64. assert tz1._start_delta != tz2._start_delta
  65. assert tz1._end_delta != tz2._end_delta