1
# -*- coding: utf-8 -*-
2 84
"""
3
Tests for implementation details, not necessarily part of the user-facing
4
API.
5

6
The motivating case for these tests is #483, where we want to smoke-test
7
code that may be difficult to reach through the standard API calls.
8
"""
9

10 84
import unittest
11 84
import sys
12

13 84
import pytest
14

15 84
from dateutil.parser._parser import _ymd
16 84
from dateutil import tz
17

18 84
IS_PY32 = sys.version_info[0:2] == (3, 2)
19

20

21 84
class TestYMD(unittest.TestCase):
22

23
    # @pytest.mark.smoke
24 84
    def test_could_be_day(self):
25 84
        ymd = _ymd('foo bar 124 baz')
26

27 84
        ymd.append(2, 'M')
28 84
        assert ymd.has_month
29 84
        assert not ymd.has_year
30 84
        assert ymd.could_be_day(4)
31 84
        assert not ymd.could_be_day(-6)
32 84
        assert not ymd.could_be_day(32)
33

34
        # Assumes leap year
35 84
        assert ymd.could_be_day(29)
36

37 84
        ymd.append(1999)
38 84
        assert ymd.has_year
39 84
        assert not ymd.could_be_day(29)
40

41 84
        ymd.append(16, 'D')
42 84
        assert ymd.has_day
43 84
        assert not ymd.could_be_day(1)
44

45 84
        ymd = _ymd('foo bar 124 baz')
46 84
        ymd.append(1999)
47 84
        assert ymd.could_be_day(31)
48

49

50
###
51
# Test that private interfaces in _parser are deprecated properly
52 84
@pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
53 27
def test_parser_private_warns():
54 84
    from dateutil.parser import _timelex, _tzparser
55 84
    from dateutil.parser import _parsetz
56

57 84
    with pytest.warns(DeprecationWarning):
58 84
        _tzparser()
59

60 84
    with pytest.warns(DeprecationWarning):
61 84
        _timelex('2014-03-03')
62

63 84
    with pytest.warns(DeprecationWarning):
64 84
        _parsetz('+05:00')
65

66

67 84
@pytest.mark.skipif(IS_PY32, reason='pytest.warns not supported on Python 3.2')
68 27
def test_parser_parser_private_not_warns():
69 84
    from dateutil.parser._parser import _timelex, _tzparser
70 84
    from dateutil.parser._parser import _parsetz
71

72 84
    with pytest.warns(None) as recorder:
73 84
        _tzparser()
74 84
        assert len(recorder) == 0
75

76 84
    with pytest.warns(None) as recorder:
77 84
        _timelex('2014-03-03')
78

79 84
        assert len(recorder) == 0
80

81 84
    with pytest.warns(None) as recorder:
82 84
        _parsetz('+05:00')
83 84
        assert len(recorder) == 0
84

85

86 84
@pytest.mark.tzstr
87 27
def test_tzstr_internal_timedeltas():
88 84
    with pytest.warns(tz.DeprecatedTzFormatWarning):
89 84
        tz1 = tz.tzstr("EST5EDT,5,4,0,7200,11,-3,0,7200")
90

91 84
    with pytest.warns(tz.DeprecatedTzFormatWarning):
92 84
        tz2 = tz.tzstr("EST5EDT,4,1,0,7200,10,-1,0,7200")
93

94 84
    assert tz1._start_delta != tz2._start_delta
95 84
    assert tz1._end_delta != tz2._end_delta

Read our documentation on viewing source code .

Loading