Code

updated spanish.nsh and inkscape.nsi to reflect latest file-changes
[inkscape.git] / trunk / share / extensions / test / svgcalendar.test.py
1 #!/usr/bin/env python\r
3 import sys
4 sys.path.append('..') # this line allows to import the extension code
6 import unittest, calendar
7 from svgcalendar import *
9 class CalendarArguments(unittest.TestCase):
11   #def setUp(self):
13   def test_default_names_list(self):
14     args = [ 'minimal-blank.svg' ]
15     e = SVGCalendar()
16     e.affect( args, False )
17     self.assertEqual( e.options.month_names[0], 'January' )
18     self.assertEqual( e.options.month_names[11], 'December' )
19     self.assertEqual( e.options.day_names[0], 'Sun' )
20     self.assertEqual( e.options.day_names[6], 'Sat' )
22   def test_modifyed_names_list(self):
23     args = [
24       '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
25       '--day-names=DOM SEG TER QUA QUI SEX SAB',
26       'minimal-blank.svg'
27       ]
28     e = SVGCalendar()
29     e.affect( args, False )
30     self.assertEqual( e.options.month_names[0], 'JAN' )
31     self.assertEqual( e.options.month_names[11], 'DEZ' )
32     self.assertEqual( e.options.day_names[0], 'DOM' )
33     self.assertEqual( e.options.day_names[6], 'SAB' )
35   def test_starting_or_ending_spaces_must_not_affect_names_list(self):
36     args = [
37       '--month-names= JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ ',
38       '--day-names=  DOM SEG TER QUA QUI SEX SAB  ',
39       'minimal-blank.svg'
40       ]
41     e = SVGCalendar()
42     e.affect( args, False )
43     self.assertEqual( e.options.month_names[0], 'JAN' )
44     self.assertEqual( e.options.month_names[11], 'DEZ' )
45     self.assertEqual( e.options.day_names[0], 'DOM' )
46     self.assertEqual( e.options.day_names[6], 'SAB' )
48   def test_inner_extra_spaces_must_not_affect_names_list(self):
49     args = [
50       '--month-names=JAN FEV    MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
51       '--day-names=DOM SEG    TER QUA QUI SEX SAB',
52       'minimal-blank.svg'
53       ]
54     e = SVGCalendar()
55     e.affect( args, False )
56     self.assertEqual( e.options.month_names[0], 'JAN' )
57     self.assertEqual( e.options.month_names[2], 'MAR' )
58     self.assertEqual( e.options.month_names[11], 'DEZ' )
59     self.assertEqual( e.options.day_names[0], 'DOM' )
60     self.assertEqual( e.options.day_names[2], 'TER' )
61     self.assertEqual( e.options.day_names[6], 'SAB' )
63   def test_default_year_must_be_the_current_year(self):
64     args = [ 'minimal-blank.svg' ]
65     e = SVGCalendar()
66     e.affect( args, False )
67     self.assertEqual( e.options.year, datetime.today().year )
69   def test_option_year_equal_0_is_converted_to_current_year(self):
70     args = [ '--year=0', 'minimal-blank.svg' ]
71     e = SVGCalendar()
72     e.affect( args, False )
73     self.assertEqual( e.options.year, datetime.today().year )
75   def test_option_year_2000_configuration(self):
76     args = [ '--year=2000', 'minimal-blank.svg' ]
77     e = SVGCalendar()
78     e.affect( args, False )
79     self.assertEqual( e.options.year, 2000 )
81   def test_default_week_start_day(self):
82     args = [ 'minimal-blank.svg' ]
83     e = SVGCalendar()
84     e.affect( args, False )
85     self.assertEqual( calendar.firstweekday(), 6 )
87   def test_configuring_week_start_day(self):
88     args = [ '--start-day=sun', 'minimal-blank.svg' ]
89     e = SVGCalendar()
90     e.affect( args, False )
91     self.assertEqual( calendar.firstweekday(), 6 )
92     args = [ '--start-day=mon', 'minimal-blank.svg' ]
93     e = SVGCalendar()
94     e.affect( args, False )
95     self.assertEqual( calendar.firstweekday(), 0 )
97 class CalendarMethods(unittest.TestCase):
99   def test_recognize_a_weekend(self):
100     args = [ '--start-day=sun', '--weekend=sat+sun', 'minimal-blank.svg' ]
101     e = SVGCalendar()
102     e.affect( args, False )
103     self.assertTrue(  e.is_weekend(0), 'Sunday is weekend in this configuration' )
104     self.assertTrue(  e.is_weekend(6), 'Saturday is weekend in this configuration' )
105     self.assertFalse( e.is_weekend(1), 'Monday is NOT weekend' )
107 if __name__ == '__main__':
108   unittest.main()