dateutil / dateutil
1
# -*- coding: utf-8 -*-
2 20
"""
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 20
import unittest
11 20
import sys
12

13 20
import pytest
14

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

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

20

21 20
class TestYMD(unittest.TestCase):
22

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

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

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

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

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

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

49

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

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

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

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

66

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

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

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

79 20
        assert len(recorder) == 0
80

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

85

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

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

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

Read our documentation on viewing source code .

Loading