2ebfcf72203f94f579931a9cfe6658a65ca5027daurium#!/usr/bin/env python
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eauriumimport sys
80d884facc03aa44a6f70dcba14d83643e52916eauriumsys.path.append('..') # this line allows to import the extension code
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eauriumimport unittest, calendar
80d884facc03aa44a6f70dcba14d83643e52916eauriumfrom svgcalendar import *
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eauriumclass CalendarArguments(unittest.TestCase):
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium #def setUp(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_default_names_list(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[0], 'January' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[11], 'December' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[0], 'Sun' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[6], 'Sat' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_modifyed_names_list(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--day-names=DOM SEG TER QUA QUI SEX SAB',
80d884facc03aa44a6f70dcba14d83643e52916eaurium 'minimal-blank.svg'
80d884facc03aa44a6f70dcba14d83643e52916eaurium ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[0], 'JAN' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[11], 'DEZ' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[0], 'DOM' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[6], 'SAB' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_starting_or_ending_spaces_must_not_affect_names_list(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--month-names= JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ ',
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--day-names= DOM SEG TER QUA QUI SEX SAB ',
80d884facc03aa44a6f70dcba14d83643e52916eaurium 'minimal-blank.svg'
80d884facc03aa44a6f70dcba14d83643e52916eaurium ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[0], 'JAN' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[11], 'DEZ' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[0], 'DOM' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[6], 'SAB' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_inner_extra_spaces_must_not_affect_names_list(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--month-names=JAN FEV MAR ABR MAI JUN JUL AGO SET OUT NOV DEZ',
80d884facc03aa44a6f70dcba14d83643e52916eaurium '--day-names=DOM SEG TER QUA QUI SEX SAB',
80d884facc03aa44a6f70dcba14d83643e52916eaurium 'minimal-blank.svg'
80d884facc03aa44a6f70dcba14d83643e52916eaurium ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[0], 'JAN' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[2], 'MAR' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.month_names[11], 'DEZ' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[0], 'DOM' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[2], 'TER' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.day_names[6], 'SAB' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_default_year_must_be_the_current_year(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.year, datetime.today().year )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_option_year_equal_0_is_converted_to_current_year(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ '--year=0', 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.year, datetime.today().year )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_option_year_2000_configuration(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ '--year=2000', 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( e.options.year, 2000 )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_default_week_start_day(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( calendar.firstweekday(), 6 )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_configuring_week_start_day(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ '--start-day=sun', 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( calendar.firstweekday(), 6 )
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ '--start-day=mon', 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertEqual( calendar.firstweekday(), 0 )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eauriumclass CalendarMethods(unittest.TestCase):
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eaurium def test_recognize_a_weekend(self):
80d884facc03aa44a6f70dcba14d83643e52916eaurium args = [ '--start-day=sun', '--weekend=sat+sun', 'minimal-blank.svg' ]
80d884facc03aa44a6f70dcba14d83643e52916eaurium e = SVGCalendar()
80d884facc03aa44a6f70dcba14d83643e52916eaurium e.affect( args, False )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertTrue( e.is_weekend(0), 'Sunday is weekend in this configuration' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertTrue( e.is_weekend(6), 'Saturday is weekend in this configuration' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium self.assertFalse( e.is_weekend(1), 'Monday is NOT weekend' )
80d884facc03aa44a6f70dcba14d83643e52916eaurium
80d884facc03aa44a6f70dcba14d83643e52916eauriumif __name__ == '__main__':
80d884facc03aa44a6f70dcba14d83643e52916eaurium unittest.main()
80d884facc03aa44a6f70dcba14d83643e52916eaurium