From: aurium Date: Thu, 22 Jan 2009 22:12:55 +0000 (+0000) Subject: * Extension test dir X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=80d884facc03aa44a6f70dcba14d83643e52916e;p=inkscape.git * Extension test dir * test for svgcalendar * minimal-blank.svg --- diff --git a/share/extensions/test/minimal-blank.svg b/share/extensions/test/minimal-blank.svg new file mode 100644 index 000000000..1fc27fb32 --- /dev/null +++ b/share/extensions/test/minimal-blank.svg @@ -0,0 +1 @@ + diff --git a/share/extensions/test/svgcalendar.test.py b/share/extensions/test/svgcalendar.test.py new file mode 100755 index 000000000..cb2054754 --- /dev/null +++ b/share/extensions/test/svgcalendar.test.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python + +import sys +sys.path.append('..') # this line allows to import the extension code + +import unittest, calendar +from svgcalendar import * + +class CalendarArguments(unittest.TestCase): + + #def setUp(self): + + def test_default_names_list(self): + args = [ 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.month_names[0], 'January' ) + self.assertEqual( e.options.month_names[11], 'December' ) + self.assertEqual( e.options.day_names[0], 'Sun' ) + self.assertEqual( e.options.day_names[6], 'Sat' ) + + def test_modifyed_names_list(self): + args = [ + '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ', + '--day-names=DOM SEG TER QUA QUI SEX SAB', + 'minimal-blank.svg' + ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.month_names[0], 'JAN' ) + self.assertEqual( e.options.month_names[11], 'DEZ' ) + self.assertEqual( e.options.day_names[0], 'DOM' ) + self.assertEqual( e.options.day_names[6], 'SAB' ) + + def test_starting_or_ending_spaces_must_not_affect_names_list(self): + args = [ + '--month-names= JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ ', + '--day-names= DOM SEG TER QUA QUI SEX SAB ', + 'minimal-blank.svg' + ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.month_names[0], 'JAN' ) + self.assertEqual( e.options.month_names[11], 'DEZ' ) + self.assertEqual( e.options.day_names[0], 'DOM' ) + self.assertEqual( e.options.day_names[6], 'SAB' ) + + def test_inner_extra_spaces_must_not_affect_names_list(self): + args = [ + '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ', + '--day-names=DOM SEG TER QUA QUI SEX SAB', + 'minimal-blank.svg' + ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.month_names[0], 'JAN' ) + self.assertEqual( e.options.month_names[2], 'MAR' ) + self.assertEqual( e.options.month_names[11], 'DEZ' ) + self.assertEqual( e.options.day_names[0], 'DOM' ) + self.assertEqual( e.options.day_names[2], 'TER' ) + self.assertEqual( e.options.day_names[6], 'SAB' ) + + def test_default_year_must_be_the_current_year(self): + args = [ 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.year, datetime.today().year ) + + def test_option_year_equal_0_is_converted_to_current_year(self): + args = [ '--year=0', 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.year, datetime.today().year ) + + def test_option_year_2000_configuration(self): + args = [ '--year=2000', 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( e.options.year, 2000 ) + + def test_default_week_start_day(self): + args = [ 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( calendar.firstweekday(), 6 ) + + def test_configuring_week_start_day(self): + args = [ '--start-day=sun', 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( calendar.firstweekday(), 6 ) + args = [ '--start-day=mon', 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertEqual( calendar.firstweekday(), 0 ) + +class CalendarMethods(unittest.TestCase): + + def test_recognize_a_weekend(self): + args = [ '--start-day=sun', '--weekend=sat+sun', 'minimal-blank.svg' ] + e = SVGCalendar() + e.affect( args, False ) + self.assertTrue( e.is_weekend(0), 'Sunday is weekend in this configuration' ) + self.assertTrue( e.is_weekend(6), 'Saturday is weekend in this configuration' ) + self.assertFalse( e.is_weekend(1), 'Monday is NOT weekend' ) + +if __name__ == '__main__': + unittest.main() +