1# coding=utf-8 2""" 3All tests for the svg calendar extension 4""" 5import calendar 6import datetime 7 8from svgcalendar import Calendar 9from inkex.tester import ComparisonMixin, TestCase 10from inkex.tester.filters import CompareOrderIndependentStyle, CompareNumericFuzzy 11from inkex.tester.mock import MockMixin 12 13class FrozenDateTime(datetime.datetime): 14 @classmethod 15 def today(cls): 16 return cls(2019, 11, 5) 17 18class CalendarArguments(ComparisonMixin, TestCase): 19 """Test arguments to calendar extensions""" 20 effect_class = Calendar 21 compare_filters = [CompareOrderIndependentStyle(), CompareNumericFuzzy()] 22 comparisons = [()] 23 mocks = [ 24 (datetime, 'datetime', FrozenDateTime) 25 ] 26 27 def test_default_names_list(self): 28 """Test default names""" 29 effect = self.assertEffect() 30 self.assertEqual(effect.options.month_names[0], 'January') 31 self.assertEqual(effect.options.month_names[11], 'December') 32 self.assertEqual(effect.options.day_names[0], 'Sun') 33 self.assertEqual(effect.options.day_names[6], 'Sat') 34 self.assertEqual(effect.options.year, datetime.datetime.today().year) 35 self.assertEqual(calendar.firstweekday(), 6) 36 37 def test_modifyed_names_list(self): 38 """Test modified names list""" 39 effect = self.assertEffect(args=[ 40 '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ', 41 '--day-names=DOM SEG TER QUA QUI SEX SAB', 42 ]) 43 self.assertEqual(effect.options.month_names[0], 'JAN') 44 self.assertEqual(effect.options.month_names[11], 'DEZ') 45 self.assertEqual(effect.options.day_names[0], 'DOM') 46 self.assertEqual(effect.options.day_names[6], 'SAB') 47 48 def test_starting_names_list(self): 49 """Starting or ending spaces must not affect names""" 50 effect = self.assertEffect(args=[ 51 '--month-names= JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ ', 52 '--day-names= DOM SEG TER QUA QUI SEX SAB ', 53 ]) 54 self.assertEqual(effect.options.month_names[0], 'JAN') 55 self.assertEqual(effect.options.month_names[11], 'DEZ') 56 self.assertEqual(effect.options.day_names[0], 'DOM') 57 self.assertEqual(effect.options.day_names[6], 'SAB') 58 59 def test_inner_extra_spaces(self): 60 """Extra spaces must not affect names""" 61 effect = self.assertEffect(args=[ 62 '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ', 63 '--day-names=DOM SEG TER QUA QUI SEX SAB', 64 ]) 65 self.assertEqual(effect.options.month_names[0], 'JAN') 66 self.assertEqual(effect.options.month_names[2], 'MAR') 67 self.assertEqual(effect.options.month_names[11], 'DEZ') 68 self.assertEqual(effect.options.day_names[0], 'DOM') 69 self.assertEqual(effect.options.day_names[2], 'TER') 70 self.assertEqual(effect.options.day_names[6], 'SAB') 71 72 def test_converted_year_zero(self): 73 """Year equal to 0 is converted to correct year""" 74 effect = self.assertEffect(args=['--year=0']) 75 self.assertEqual(effect.options.year, datetime.datetime.today().year) 76 77 def test_converted_year_thousand(self): 78 """Year equal to 2000 configuration""" 79 effect = self.assertEffect(args=['--year=2000']) 80 self.assertEqual(effect.options.year, 2000) 81 82 def test_configuring_week_start_sun(self): 83 """Week start is set to Sunday""" 84 self.assertEffect(args=['--start-day=sun']) 85 self.assertEqual(calendar.firstweekday(), 6) 86 87 def test_configuring_week_start_mon(self): 88 """Week start is set to Monday""" 89 self.assertEffect(args=['--start-day=mon']) 90 self.assertEqual(calendar.firstweekday(), 0) 91 92 def test_recognize_a_weekend(self): 93 """Recognise a weekend""" 94 effect = self.assertEffect(args=[ 95 '--start-day=sun', '--weekend=sat+sun', 96 ]) 97 self.assertTrue(effect.is_weekend(0), 'Sunday is weekend in this configuration') 98 self.assertTrue(effect.is_weekend(6), 'Saturday is weekend in this configuration') 99 self.assertFalse(effect.is_weekend(1), 'Monday is NOT weekend') 100