コード例 #1
0
    def enter(self, *args):
        """Validate the current edit widget"""

        ent, cal = self.stack[0]
        if ent.get_text():
            txt = ent.get_text()

            obj = TimeDelta()
            txt2 = obj.parse(txt)

            if txt2 == txt:
                obj = DateRange(txt)

            self.push(obj)
            ent.grab_focus()
コード例 #2
0
def test_timedelta_dey_month_year_good(value):
    td = TimeDelta(value, value, value)
    assert td.day == value
    assert td.month == value
    assert td.year == value
    assert str(td) == f"{value}.{value}.{value}"
コード例 #3
0
def test_timedelta_dey_month_year_bad():
    with pytest.raises(TypeError):
        TimeDelta("str", 1, 1)
    with pytest.raises(ValueError):
        TimeDelta(-1, 1, 1)
コード例 #4
0
    with pytest.raises(err):
        d.day = day
    with pytest.raises(err):
        d.month = month
    with pytest.raises(err):
        d.year = year


def test_dey_month_year_bad2():
    d = Date(29, 2, 1600)
    with pytest.raises(ValueError):
        d.year = 1999


@pytest.mark.parametrize("rez, date, time", [
    ("29.2.1600", Date(1, 2, 1600), TimeDelta(28)),
    ("4.3.6", Date(1, 1, 1), TimeDelta(1888)),
    ("11.1.1601", Date(12, 12, 1600), TimeDelta(30)),
    ("2.1.2", Date(1, 12, 1), TimeDelta(1, 1)),
    ("1.12.1", Date(1, 1, 1), TimeDelta(months=11))
])
def test_add_good(rez, date, time):
    """Проверяем операцию +"""
    assert rez == str(date + time)


def test_add_bad():
    """Проверяем операцию +"""
    with pytest.raises(TypeError):
        Date(1, 2, 1600) + 5
コード例 #5
0
def test_negative_years_setter():
    my_timedelta = TimeDelta(1, 1, 1)
    with pytest.raises(NotImplementedError) as excinfo:
        my_timedelta.years = -42
    assert 'Addition of a negative "years" value is not implemented yet.' in str(
        excinfo.value)
コード例 #6
0
def test_str_function_timedelta(days, months, years):
    check = str(TimeDelta(days, months, years))
    assert check == f'{days}.{months}.{years}'
コード例 #7
0
def test_evil_years_setter(years):
    my_timedelta = TimeDelta(1, 1, 1)
    with pytest.raises(TypeError) as excinfo:
        my_timedelta.years = years
    assert 'You can input only an integer for a "years" value.' in str(
        excinfo.value)
コード例 #8
0
def test_init_correct_timedelta(days, months, years):
    my_timedelta = TimeDelta(days, months, years)
    assert my_timedelta.days == days
    assert my_timedelta.months == months
    assert my_timedelta.years == years
コード例 #9
0
def test_evil_months_setter(months):
    my_timedelta = TimeDelta(1, 1, 1)
    with pytest.raises(TypeError) as excinfo:
        my_timedelta.months = months
    assert 'You can input only an integer for a "months" value.' in str(
        excinfo.value)
コード例 #10
0
def test_correct_years_setter(years):
    my_timedelta = TimeDelta(1, 1, 1)
    my_timedelta.years = years
    assert my_timedelta.years == years
コード例 #11
0
def test_correct_months_setter(months):
    my_timedelta = TimeDelta(1, 1, 1)
    my_timedelta.months = months
    assert my_timedelta.months == months
コード例 #12
0
def test_evil_days_setter(days):
    my_timedelta = TimeDelta(1, 1, 1)
    with pytest.raises(TypeError) as excinfo:
        my_timedelta.days = days
    assert 'You can input only an integer for a "days" value.' in str(
        excinfo.value)
コード例 #13
0
def test_correct_days_setter(days):
    my_timedelta = TimeDelta(1, 1, 1)
    my_timedelta.days = days
    assert my_timedelta.days == days
コード例 #14
0
def test_repr_function_timedelta(days, months, years):
    check = repr(TimeDelta(days, months, years))
    assert check == f'TimeDelta({days}, {months}, {years})'
コード例 #15
0
    result = first_date - second_date
    assert result == expected


# Test related to "__sub__ method"
def test_correct_type_sub():
    first_date = Date(31, 12, 2020)
    with pytest.raises(TypeError) as excinfo:
        first_date - 'cow'
    assert 'Second parameter should be of class "Date".' in str(excinfo.value)


# Test related to "__add__ method" and "__special_for_add_and_iadd private method"
@pytest.mark.parametrize(
    "date, timedelta, expected",
    [(Date(31, 12, 2020), TimeDelta(None, None, None), Date(31, 12, 2020)),
     (Date(29, 2, 2004), TimeDelta(95, 8, 5), Date(1, 2, 2010)),
     (Date(5, 3, 2016), TimeDelta(None, 30, None), Date(5, 9, 2018)),
     (Date(15, 11, 2016), TimeDelta(None, 27, None), Date(15, 2, 2019)),
     (Date(15, 2, 2016), TimeDelta(None, None, 100), Date(15, 2, 2116)),
     (Date(15, 11, 2016), TimeDelta(100, None, None), Date(23, 2, 2017)),
     (Date(31, 1, 2016), TimeDelta(None, 1, None), Date(29, 2, 2016))])
def test_add(date, timedelta, expected):
    result = date + timedelta
    assert result.day == expected.day
    assert result.month == expected.month
    assert result.year == expected.year


# Test related to "__add__ method"
def test_correct_type_add():