<s> import unittest <EOL> from datetime import datetime , timedelta <EOL> from itertools import islice <EOL> from pomodoro_calculator import PomodoroCalculator , humanise_seconds <EOL> from freezegun import freeze_time <EOL> class PomodoroTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . calculator = PomodoroCalculator ( end = '<STR_LIT>' ) <EOL> def test_retriever_class_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( '<STR_LIT>' in globals ( ) ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_create_datetime_with_hours ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_datetime ( '<STR_LIT>' ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:15> ) , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_create_datetime_with_hours_and_minutes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_datetime ( '<STR_LIT>' ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:30> ) , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_create_datetime_with_hours_minutes_and_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_datetime ( '<STR_LIT>' ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:30> , <NUM_LIT> ) , <EOL> ) <EOL> def test_create_timedelta_with_hours ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_timedelta ( '<STR_LIT>' ) , <EOL> timedelta ( hours = <NUM_LIT:15> ) , <EOL> ) <EOL> def test_create_timedelta_with_hours_and_minutes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_timedelta ( '<STR_LIT>' ) , <EOL> timedelta ( hours = <NUM_LIT:15> , minutes = <NUM_LIT:30> ) , <EOL> ) <EOL> def test_create_timedelta_with_hours_minutes_and_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> self . calculator . _create_timedelta ( '<STR_LIT>' ) , <EOL> timedelta ( hours = <NUM_LIT:15> , minutes = <NUM_LIT:30> , seconds = <NUM_LIT> ) , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_start_time_initialisation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' ) . start , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:30> ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' , start = '<STR_LIT>' ) . start , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:30> ) , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_end_time_initialisation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' ) . end , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:30> ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' , start = '<STR_LIT>' ) . end , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:30> ) , <EOL> ) <EOL> self . assertEqual ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' , interval = True ) . end , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:30> ) , <EOL> ) <EOL> def test_short_break_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> calculator = PomodoroCalculator ( end = '<STR_LIT>' , short_break = <NUM_LIT:10> ) <EOL> self . assertEqual ( self . calculator . short_break_seconds , <NUM_LIT:5> * <NUM_LIT> ) <EOL> self . assertEqual ( calculator . short_break_seconds , <NUM_LIT:10> * <NUM_LIT> ) <EOL> def test_long_break_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> calculator = PomodoroCalculator ( end = '<STR_LIT>' , long_break = <NUM_LIT:10> ) <EOL> self . assertEqual ( self . calculator . long_break_seconds , <NUM_LIT:15> * <NUM_LIT> ) <EOL> self . assertEqual ( calculator . long_break_seconds , <NUM_LIT:10> * <NUM_LIT> ) <EOL> def test_total_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> calculator = PomodoroCalculator ( end = '<STR_LIT>' , start = '<STR_LIT>' ) <EOL> self . assertEqual ( calculator . long_break_seconds , <NUM_LIT:15> * <NUM_LIT> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_get_item ( self ) : <EOL> """<STR_LIT>""" <EOL> pomodoro = PomodoroCalculator ( end = '<STR_LIT>' ) <EOL> short_break = PomodoroCalculator ( end = '<STR_LIT>' ) <EOL> long_break = PomodoroCalculator ( end = '<STR_LIT>' ) <EOL> self . assertDictEqual ( <EOL> pomodoro . _get_item ( <NUM_LIT> , '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> { <EOL> '<STR_LIT:index>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> '<STR_LIT:end>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> ) <EOL> self . assertDictEqual ( <EOL> short_break . _get_item ( <NUM_LIT> , '<STR_LIT>' , <NUM_LIT:2> ) , <EOL> { <EOL> '<STR_LIT:index>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> '<STR_LIT:end>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:6> ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> ) <EOL> self . assertDictEqual ( <EOL> long_break . _get_item ( <NUM_LIT> , '<STR_LIT>' , <NUM_LIT:3> ) , <EOL> { <EOL> '<STR_LIT:index>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> '<STR_LIT:end>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:16> ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori_none ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIsNone ( <EOL> PomodoroCalculator ( end = '<STR_LIT>' ) . pomodori_schedule ( ) <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori_single_pomodoro ( self ) : <EOL> """<STR_LIT>""" <EOL> pomodori = PomodoroCalculator ( end = '<STR_LIT>' ) . pomodori_schedule ( ) <EOL> self . assertEqual ( len ( pomodori [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( pomodori [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . get ( '<STR_LIT:type>' ) , '<STR_LIT>' ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori_never_ends_with_break ( self ) : <EOL> """<STR_LIT>""" <EOL> times = [ <EOL> '<STR_LIT>' . format ( h , m ) <EOL> for m in range ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> for h in range ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> ] <EOL> for time in times : <EOL> pomodori = PomodoroCalculator ( end = time ) . pomodori_schedule ( ) <EOL> if pomodori : <EOL> self . assertEqual ( <EOL> pomodori [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . get ( '<STR_LIT:type>' ) , <EOL> '<STR_LIT>' , <EOL> ) <EOL> self . assertNotEqual ( <EOL> pomodori [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . get ( '<STR_LIT:type>' ) , <EOL> '<STR_LIT>' , <EOL> ) <EOL> self . assertNotEqual ( <EOL> pomodori [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . get ( '<STR_LIT:type>' ) , <EOL> '<STR_LIT>' , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori ( self ) : <EOL> """<STR_LIT>""" <EOL> pomodori = PomodoroCalculator ( end = '<STR_LIT>' ) . pomodori_schedule ( ) <EOL> expected_segments = [ <EOL> ( pomodori [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ '<STR_LIT:start>' ] , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ) , <EOL> ( pomodori [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ '<STR_LIT:end>' ] , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ) , <EOL> ( len ( [ e for e in pomodori [ '<STR_LIT>' ] if e [ '<STR_LIT:type>' ] == '<STR_LIT>' ] ) , <NUM_LIT:5> ) , <EOL> ( len ( [ e for e in pomodori [ '<STR_LIT>' ] if e [ '<STR_LIT:type>' ] == '<STR_LIT>' ] ) , <NUM_LIT:3> ) , <EOL> ( len ( [ e for e in pomodori [ '<STR_LIT>' ] if e [ '<STR_LIT:type>' ] == '<STR_LIT>' ] ) , <NUM_LIT:1> ) , <EOL> ] <EOL> for expected_segment in expected_segments : <EOL> self . assertEqual ( expected_segment [ <NUM_LIT:0> ] , expected_segment [ <NUM_LIT:1> ] ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori_meta_data ( self ) : <EOL> """<STR_LIT>""" <EOL> pomodori = PomodoroCalculator ( end = '<STR_LIT>' ) . pomodori_schedule ( ) <EOL> del pomodori [ '<STR_LIT>' ] <EOL> self . assertDictEqual ( <EOL> pomodori , <EOL> { <EOL> '<STR_LIT:end>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:2> ) , <EOL> '<STR_LIT:start>' : datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_pomodori_does_not_overflow ( self ) : <EOL> """<STR_LIT>""" <EOL> pomodori = PomodoroCalculator ( end = '<STR_LIT>' ) . pomodori_schedule ( ) <EOL> self . assertLess ( <EOL> pomodori [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] [ '<STR_LIT:end>' ] , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:15> ) <EOL> ) <EOL> def test_pomodori_segment_generator ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertListEqual ( <EOL> list ( islice ( self . calculator . pomodori_segments ( ) , <NUM_LIT:16> ) ) , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ) <EOL> def test_humanise_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) <EOL> self . assertEqual ( humanise_seconds ( <NUM_LIT> ) , '<STR_LIT>' ) </s>
