def test_handle_week_works_for_full_week(infile_wrapper): extr = Extract(infile_wrapper) extr.line_as_list = [ '12/4/2016', '', '', '', '', '', '', '', '', '', 'b', '23:45', '', 'w', '3:45', '4.00', 'w', '2:00', '2.75', 'b', '0:00', '9.00' ] assert not extr._handle_week([])
def test_init_with_good_argument_succeeds(): filename = '/dev/null' opened_file = open(filename) extr = Extract(opened_file) for line in extr.infile: line += 'x' break assert isinstance(extr, Extract)
def test_lines_in_weeks_out(infile_wrapper, capfd): """ >==> THIS TEST WILL FAIL UNLESS PYTEST IS RUN WITH -s SWITCH <==< """ infile = open_infile(infile_wrapper) extract = Extract(infile) extract.lines_in_weeks_out() fd1, fd2 = capfd.readouterr() assert fd1 == ''' Week of Sunday, 2016-12-04: ========================== 2016-12-04 2016-12-05 2016-12-06 2016-12-07 action: Y, time: 23:45 2016-12-08 action: w, time: 3:45, hours: 4.00 action: s, time: 4:45 action: w, time: 6:15, hours: 1.50 action: s, time: 11:30 action: w, time: 12:15, hours: 0.75 action: s, time: 16:45 action: w, time: 17:30, hours: 0.75 action: s, time: 21:00 action: w, time: 21:30, hours: 0.50 action: b, time: 23:15, hours: 7.50 2016-12-09 action: w, time: 2:00, hours: 2.75 action: s, time: 3:30 action: w, time: 8:45, hours: 5.25 action: s, time: 19:30 action: w, time: 20:30, hours: 1.00 2016-12-10 action: b, time: 0:00, hours: 9.00 action: w, time: 5:15, hours: 5.25 action: s, time: 10:30 action: w, time: 11:30, hours: 1.00 action: s, time: 16:00 action: w, time: 17:00, hours: 1.00 ''' assert fd2 == ''
def test_init_with_bad_argument_fails(): filename = None extr = Extract(filename) with pytest.raises(AttributeError): _ = extr.infile.getline()
def test_match_event_line_returns_false_on_non_action_input(): line = '=' * 18 assert not bool(Extract._match_event_line(line))
def test_match_event_line_returns_false_on_2_element_w_line_input(): line = 'action: w, time: 11:45' assert not bool(Extract._match_event_line(line))
def extract(): return Extract(FakeFileReadWrapper(''))
def test_match_event_line_returns_false_on_3_element_s_line_input(): line = 'action: s, time: 12:00, hours: 6.00' assert not bool(Extract._match_event_line(line))
def test_match_event_line_returns_true_on_3_element_w_line_input(): line = 'action: w, time: 11:00, hours: 10.50' assert bool(Extract._match_event_line(line))
def test_match_event_line_returns_true_on_2_element_s_line_input(): line = 'action: s, time: 4:25' assert bool(Extract._match_event_line(line))
def test_match_event_line_returns_true_on_3_element_b_line_input(): line = 'action: b, time: 4:25, hours: 6.00' assert bool(Extract._match_event_line(line))
def test_match_complete_b_event_line_returns_false_on_non_event_line_input(): line = 'cowabunga!!!' assert not bool(Extract._match_complete_b_event_line(line))
def test_match_complete_b_event_line_returns_false_on_non_b_event_line_input(): line = 'action: s, time: 17:25' assert not bool(Extract._match_complete_b_event_line(line))
def test_match_complete_b_event_line_returns_true_on_complete_b_event_line(): line = 'action: b, time: 21:45, hours: 3.75' assert bool(Extract._match_complete_b_event_line(line))
def test_get_day_header(day=Day(datetime.date(2018, 10, 14), [])): assert Extract._get_day_header(day) == ' 2018-10-14'
def test_handle_week_works_for_empty_week(infile_wrapper): extr = Extract(infile_wrapper) extr.line_as_list = [''] * 22 assert not extr._handle_week([])