summaryrefslogtreecommitdiffstats
path: root/share/extensions/tests/test_svgcalendar.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
commit35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch)
tree657d15a03cc46bd099fc2c6546a7a4ad43815d9f /share/extensions/tests/test_svgcalendar.py
parentInitial commit. (diff)
downloadinkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz
inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'share/extensions/tests/test_svgcalendar.py')
-rw-r--r--share/extensions/tests/test_svgcalendar.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/share/extensions/tests/test_svgcalendar.py b/share/extensions/tests/test_svgcalendar.py
new file mode 100644
index 0000000..e0c7d8b
--- /dev/null
+++ b/share/extensions/tests/test_svgcalendar.py
@@ -0,0 +1,99 @@
+# coding=utf-8
+"""
+All tests for the svg calendar extension
+"""
+import calendar
+import datetime
+
+from svgcalendar import Calendar
+from inkex.tester import ComparisonMixin, TestCase
+from inkex.tester.filters import CompareOrderIndependentStyle, CompareNumericFuzzy
+from inkex.tester.mock import MockMixin
+
+class FrozenDateTime(datetime.datetime):
+ @classmethod
+ def today(cls):
+ return cls(2019, 11, 5)
+
+class CalendarArguments(ComparisonMixin, TestCase):
+ """Test arguments to calendar extensions"""
+ effect_class = Calendar
+ compare_filters = [CompareOrderIndependentStyle(), CompareNumericFuzzy()]
+ comparisons = [()]
+ mocks = [
+ (datetime, 'datetime', FrozenDateTime)
+ ]
+
+ def test_default_names_list(self):
+ """Test default names"""
+ effect = self.assertEffect()
+ self.assertEqual(effect.options.month_names[0], 'January')
+ self.assertEqual(effect.options.month_names[11], 'December')
+ self.assertEqual(effect.options.day_names[0], 'Sun')
+ self.assertEqual(effect.options.day_names[6], 'Sat')
+ self.assertEqual(effect.options.year, datetime.datetime.today().year)
+ self.assertEqual(calendar.firstweekday(), 6)
+
+ def test_modifyed_names_list(self):
+ """Test modified names list"""
+ effect = self.assertEffect(args=[
+ '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
+ '--day-names=DOM SEG TER QUA QUI SEX SAB',
+ ])
+ self.assertEqual(effect.options.month_names[0], 'JAN')
+ self.assertEqual(effect.options.month_names[11], 'DEZ')
+ self.assertEqual(effect.options.day_names[0], 'DOM')
+ self.assertEqual(effect.options.day_names[6], 'SAB')
+
+ def test_starting_names_list(self):
+ """Starting or ending spaces must not affect names"""
+ effect = self.assertEffect(args=[
+ '--month-names= JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ ',
+ '--day-names= DOM SEG TER QUA QUI SEX SAB ',
+ ])
+ self.assertEqual(effect.options.month_names[0], 'JAN')
+ self.assertEqual(effect.options.month_names[11], 'DEZ')
+ self.assertEqual(effect.options.day_names[0], 'DOM')
+ self.assertEqual(effect.options.day_names[6], 'SAB')
+
+ def test_inner_extra_spaces(self):
+ """Extra spaces must not affect names"""
+ effect = self.assertEffect(args=[
+ '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
+ '--day-names=DOM SEG TER QUA QUI SEX SAB',
+ ])
+ self.assertEqual(effect.options.month_names[0], 'JAN')
+ self.assertEqual(effect.options.month_names[2], 'MAR')
+ self.assertEqual(effect.options.month_names[11], 'DEZ')
+ self.assertEqual(effect.options.day_names[0], 'DOM')
+ self.assertEqual(effect.options.day_names[2], 'TER')
+ self.assertEqual(effect.options.day_names[6], 'SAB')
+
+ def test_converted_year_zero(self):
+ """Year equal to 0 is converted to correct year"""
+ effect = self.assertEffect(args=['--year=0'])
+ self.assertEqual(effect.options.year, datetime.datetime.today().year)
+
+ def test_converted_year_thousand(self):
+ """Year equal to 2000 configuration"""
+ effect = self.assertEffect(args=['--year=2000'])
+ self.assertEqual(effect.options.year, 2000)
+
+ def test_configuring_week_start_sun(self):
+ """Week start is set to Sunday"""
+ self.assertEffect(args=['--start-day=sun'])
+ self.assertEqual(calendar.firstweekday(), 6)
+
+ def test_configuring_week_start_mon(self):
+ """Week start is set to Monday"""
+ self.assertEffect(args=['--start-day=mon'])
+ self.assertEqual(calendar.firstweekday(), 0)
+
+ def test_recognize_a_weekend(self):
+ """Recognise a weekend"""
+ effect = self.assertEffect(args=[
+ '--start-day=sun', '--weekend=sat+sun',
+ ])
+ self.assertTrue(effect.is_weekend(0), 'Sunday is weekend in this configuration')
+ self.assertTrue(effect.is_weekend(6), 'Saturday is weekend in this configuration')
+ self.assertFalse(effect.is_weekend(1), 'Monday is NOT weekend')