Esempio n. 1
0
 def test_420_replace(self):
     for test_row in iso_test_data[:33]:   # take Calendrical Calculations tests data only (other may make replace fail, as in the next tests method)
         year = test_row[1]
         week = test_row[2]
         day = test_row[3]
         iso = IsoCalendar(year, week, day)
         assert iso.replace() == IsoCalendar(year, week, day)
         assert iso.replace(year = 11) == IsoCalendar(11, week, day)
         assert iso.replace(week = 10) == IsoCalendar(year, 10, day)
         assert iso.replace(day = 2) == IsoCalendar(year, week, 2)
         assert iso.replace(week = 10, year = 11) == IsoCalendar(11, 10, day)
         assert iso.replace(day = 3, year = 11) == IsoCalendar(11, week, 3)
         assert iso.replace(day = 4, week = 10) == IsoCalendar(year, 10, 4)
         assert iso.replace(day = 1, week = 10, year = 11) == IsoCalendar(11, 10, 1)
Esempio n. 2
0
 def test_420_replace(self):
     for test_row in iso_test_data[:
                                   33]:  # take Calendrical Calculations tests data only (other may make replace fail, as in the next tests method)
         year = test_row[1]
         week = test_row[2]
         day = test_row[3]
         iso = IsoCalendar(year, week, day)
         assert iso.replace() == IsoCalendar(year, week, day)
         assert iso.replace(year=11) == IsoCalendar(11, week, day)
         assert iso.replace(week=10) == IsoCalendar(year, 10, day)
         assert iso.replace(day=2) == IsoCalendar(year, week, 2)
         assert iso.replace(week=10, year=11) == IsoCalendar(11, 10, day)
         assert iso.replace(day=3, year=11) == IsoCalendar(11, week, 3)
         assert iso.replace(day=4, week=10) == IsoCalendar(year, 10, 4)
         assert iso.replace(day=1, week=10,
                            year=11) == IsoCalendar(11, 10, 1)
Esempio n. 3
0
 def test_426_replace_invalid_values(self):
     iso1 = IsoCalendar(11, 10, 4)
     with pytest.raises(ValueError):
         iso1.replace(week=0)
     with pytest.raises(ValueError):
         iso1.replace(day=0)
     with pytest.raises(ValueError):
         iso1.replace(week=-1)
     with pytest.raises(ValueError):
         iso1.replace(day=-1)
     with pytest.raises(ValueError):
         iso1.replace(week=54)
     with pytest.raises(ValueError):
         iso1.replace(day=8)
     iso2 = IsoCalendar(1, 9, 2)  # short year
     with pytest.raises(ValueError):
         iso2.replace(week=53)
     iso3 = IsoCalendar(4, 9, 2)  # long year
     with pytest.raises(ValueError):
         iso3.replace(week=54)
Esempio n. 4
0
 def test_423_replace_invalid_types(self):
     iso = IsoCalendar(11, 10, 4)
     # exception for positional parameters
     with pytest.raises(TypeError):
         iso.replace(1)
     # exception with non-numeric types
     for par in ("1", (1, ), [1], {1: 1}, (), [], {}):
         with pytest.raises(TypeError):
             iso.replace(year=par)
         with pytest.raises(TypeError):
             iso.replace(week=par)
         with pytest.raises(TypeError):
             iso.replace(day=par)
     # exception with invalid numeric types
     for par in (1.0, Fraction(1, 1), Decimal(1), 1j):
         with pytest.raises(TypeError):
             iso.replace(year=par)
         with pytest.raises(TypeError):
             iso.replace(week=par)
         with pytest.raises(TypeError):
             iso.replace(day=par)
Esempio n. 5
0
 def test_426_replace_invalid_values(self):
     iso1 = IsoCalendar(11, 10, 4)
     with pytest.raises(ValueError):
         iso1.replace(week=0)
     with pytest.raises(ValueError):
         iso1.replace(day=0)
     with pytest.raises(ValueError):
         iso1.replace(week=-1)
     with pytest.raises(ValueError):
         iso1.replace(day=-1)
     with pytest.raises(ValueError):
         iso1.replace(week=54)
     with pytest.raises(ValueError):
         iso1.replace(day=8)
     iso2 = IsoCalendar(1, 9, 2)   # short year
     with pytest.raises(ValueError):
         iso2.replace(week=53)
     iso3 = IsoCalendar(4, 9, 2)   # long year
     with pytest.raises(ValueError):
         iso3.replace(week=54)
Esempio n. 6
0
 def test_423_replace_invalid_types(self):
     iso = IsoCalendar(11, 10, 4)
     # exception for positional parameters
     with pytest.raises(TypeError):
         iso.replace(1)
     # exception with non-numeric types
     for par in ("1", (1,), [1], {1:1}, (), [], {}):
         with pytest.raises(TypeError):
             iso.replace(year=par)
         with pytest.raises(TypeError):
             iso.replace(week=par)
         with pytest.raises(TypeError):
             iso.replace(day=par)
     # exception with invalid numeric types
     for par in (1.0, Fraction(1, 1), Decimal(1), 1j):
         with pytest.raises(TypeError):
             iso.replace(year=par)
         with pytest.raises(TypeError):
             iso.replace(week=par)
         with pytest.raises(TypeError):
             iso.replace(day=par)