示例#1
0
def test_month_isleap(year, exp):
    """
    month.isleap() returns True when year is a leap year, otherwise False
    """
    pytest.debug_func()
    m = nldt.month()
    assert m.isleap(year) == exp
示例#2
0
def test_month_under_days():
    """
    """
    pytest.debug_func()
    mobj = nldt.month()
    exp = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    for dnum in range(1, 13):
        assert mobj._days(dnum) == exp[dnum-1]
示例#3
0
def test_month_short_names():
    """
    month.short_names() is supposed to return a list of three letter lowercase
    month name abbreviations
    """
    pytest.debug_func()
    m = nldt.month()
    for item in m.short_names():
        assert len(item) == 3
        assert item.lower() == item
示例#4
0
def test_month_names():
    """
    nldt.month_names() returns the list of month names in order
    """
    pytest.debug_func()
    m = nldt.month()
    result = m.names()
    exp = ['january', 'february', 'march', 'april', 'may', 'june',
           'july', 'august', 'september', 'october', 'november', 'december']
    assert result == exp
示例#5
0
def test_month_days_curyear():
    """
    Verify that month.days() for february this year does the right thing
    """
    pytest.debug_func()
    mobj = nldt.month()
    now = nldt.moment()
    curyear = int(now('%Y'))
    exp = 29 if mobj.isleap(curyear) else 28
    # payload
    assert mobj.days(2) == exp
示例#6
0
def test_month_constructor():
    """
    nldt.month() constructor should return an object with dict of months
    """
    pytest.debug_func()
    m = nldt.month()
    assert hasattr(m, '_dict')
    for midx in range(1, 13):
        assert midx in m._dict
    for mname in ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
                  'jul', 'aug', 'sep', 'oct', 'nov', 'dec']:
        assert mname in m._dict
示例#7
0
def test_month_match_monthnames(inp, exp):
    """
    Test the monthnames regex against each of the month names
    """
    pytest.debug_func()
    m = nldt.month()
    rgx = m.match_monthnames()
    result = re.search(rgx, inp, re.I)
    if exp is None:
        assert result is None
    else:
        assert exp == result.group()
示例#8
0
def test_month_indexify(inp, exp):
    """
    Tests for month.indexify()
    """
    pytest.debug_func()
    mon = nldt.month()
    if isinstance(exp, Exception):
        with pytest.raises(type(exp)) as err:
            assert mon.indexify(inp) == 'something'
        assert str(exp) in str(err)
    else:
        assert mon.indexify(inp) == exp
示例#9
0
def test_month_curyear_isleap():
    """
    When year is not given, isleap should return True if the current year is
    leap, else False
    """
    pytest.debug_func()
    m = nldt.month()
    if m.days(2) == 29:
        # payload
        assert m.isleap(None)
    else:
        # payload
        assert not m.isleap(None)
示例#10
0
def test_month_days(month, year, exp):
    """
    Get the number of days in each month
    """
    pytest.debug_func()
    m = nldt.month()
    if isinstance(exp, numbers.Number):
        # payload
        assert m.days(month=month, year=year) == exp
    else:
        with pytest.raises(ValueError) as err:
            # payload
            m.days(month=month, year=year)
        assert exp in str(err)
示例#11
0
def test_month_index():
    """
    nldt.month_index() takes a month name and returns its index. On bad input,
    it will raise a KeyError.
    """
    pytest.debug_func()
    m = nldt.month()
    assert m.index('jan') == 1
    assert m.index('February') == 2
    assert m.index('marc') == 3
    assert m.index('apr') == 4
    assert m.index('May') == 5
    assert m.index('june') == 6
    assert m.index('jul') == 7
    assert m.index('August') == 8
    assert m.index('sep') == 9
    assert m.index('Octob') == 10
    assert m.index('nov') == 11
    assert m.index('December') == 12
    with pytest.raises(ValueError) as err:
        assert m.index('frobble')
    assert txt['not-indxfy'].format('frobble') in str(err)