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. import warnings
  11. from dateutil.parser._parser import _ymd
  12. from dateutil import tz
  13. IS_PY32 = sys.version_info[0:2] == (3, 2)
  14. @pytest.mark.smoke
  15. def test_YMD_could_be_day():
  16. ymd = _ymd('foo bar 124 baz')
  17. ymd.append(2, 'M')
  18. assert ymd.has_month
  19. assert not ymd.has_year
  20. assert ymd.could_be_day(4)
  21. assert not ymd.could_be_day(-6)
  22. assert not ymd.could_be_day(32)
  23. # Assumes leap year
  24. assert ymd.could_be_day(29)
  25. ymd.append(1999)
  26. assert ymd.has_year
  27. assert not ymd.could_be_day(29)
  28. ymd.append(16, 'D')
  29. assert ymd.has_day
  30. assert not ymd.could_be_day(1)
  31. ymd = _ymd('foo bar 124 baz')
  32. ymd.append(1999)
  33. assert ymd.could_be_day(31)
  34. ###
  35. # Test that private interfaces in _parser are deprecated properly
  36. @pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
  37. def test_parser_private_warns():
  38. from dateutil.parser import _timelex, _tzparser
  39. from dateutil.parser import _parsetz
  40. with pytest.warns(DeprecationWarning):
  41. _tzparser()
  42. with pytest.warns(DeprecationWarning):
  43. _timelex('2014-03-03')
  44. with pytest.warns(DeprecationWarning):
  45. _parsetz('+05:00')
  46. @pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
  47. def test_parser_parser_private_not_warns():
  48. from dateutil.parser._parser import _timelex, _tzparser
  49. from dateutil.parser._parser import _parsetz
  50. with warnings.catch_warnings():
  51. warnings.simplefilter("error")
  52. _tzparser()
  53. with warnings.catch_warnings():
  54. warnings.simplefilter("error")
  55. _timelex('2014-03-03')
  56. with warnings.catch_warnings():
  57. warnings.simplefilter("error")
  58. _parsetz('+05:00')
  59. @pytest.mark.tzstr
  60. def test_tzstr_internal_timedeltas():
  61. with pytest.warns(tz.DeprecatedTzFormatWarning):
  62. tz1 = tz.tzstr("EST5EDT,5,4,0,7200,11,-3,0,7200")
  63. with pytest.warns(tz.DeprecatedTzFormatWarning):
  64. tz2 = tz.tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200")
  65. assert tz1._start_delta != tz2._start_delta
  66. assert tz1._end_delta != tz2._end_delta