Exemple #1
0
def test_alias_before_date():
    content = """my_alias_1 1 foo bar
11.10.2013
my_alias 2 foo"""

    with pytest.raises(ParseError):
        TimesheetParser.parse(content)

    content = """# comment
11.10.2013
my_alias 2 foo"""

    lines = TimesheetParser.parse(content)
    assert len(lines) == 3
Exemple #2
0
def test_invalid_end_time_raises_parse_error():
    contents = """03.07.2017
alias_1 0845-0960 xxx
"""

    with pytest.raises(ParseError):
        TimesheetParser().parse_text(contents)
Exemple #3
0
def test_detect_formatting_padded_alias():
    line = Entry('foobar',
                 4,
                 'description',
                 text=('', '', 'foobar', '   ', '4', ' ', 'description'))
    assert TimesheetParser().entry_line_to_text(
        line) == 'foobar   4 description'
Exemple #4
0
def test_parse_entry_with_floating_duration_without_leading_part():
    contents = """03.07.2017
alias_1       .5 xxx
"""
    lines = TimesheetParser().parse_text(contents)

    assert lines[-1].hours == 0.5
Exemple #5
0
def test_detect_formatting_padded_time():
    line = Entry('foobar', (datetime.time(15, 0), datetime.time(16, 0)),
                 'description',
                 text=('', '', 'foobar', ' ', '1500-1600', '   ',
                       'description'))
    assert TimesheetParser().entry_line_to_text(
        line) == 'foobar 1500-1600   description'
Exemple #6
0
def test_parsing():
    contents = """01.01.13

foobar 0900-1000 baz
# comment
foo -1100 bar

2013/09/23
bar 10:00-? ?
foo? 2 foobar"""

    lines = TimesheetParser.parse(contents)

    assert len(lines) == 9
    assert isinstance(lines[0], DateLine)
    assert lines[0].date == datetime.date(2013, 1, 1)
    assert isinstance(lines[1], TextLine)
    assert lines[1].text == ''
    assert isinstance(lines[2], EntryLine)
    assert lines[2].alias == 'foobar'
    assert lines[2].duration == (datetime.time(9, 0), datetime.time(10, 0))
    assert lines[2].description == 'baz'
    assert isinstance(lines[3], TextLine)
    assert lines[3].text == '# comment'
    assert lines[4].alias == 'foo'
    assert lines[4].duration == (None, datetime.time(11, 0))
    assert lines[4].description == 'bar'
    assert isinstance(lines[6], DateLine)
    assert lines[6].date == datetime.date(2013, 9, 23)
    assert isinstance(lines[7], EntryLine)
    assert lines[7].duration == (datetime.time(10, 0), None)
    assert isinstance(lines[8], EntryLine)
    assert lines[8].alias == 'foo'
    assert lines[8].ignored
Exemple #7
0
def test_detect_formatting_no_alias_padding():
    line = Entry(
        'foobar',
        4,
        'description',
    )
    assert TimesheetParser().entry_line_to_text(line) == 'foobar 4 description'
Exemple #8
0
def create_timesheet(text, add_date_to_bottom=False):
    aliases_database.update({
        'foo': Mapping(mapping=(123, 456), backend='test'),
        'bar': Mapping(mapping=(12, 34), backend='test'),
    })
    parser = TimesheetParser(add_date_to_bottom=add_date_to_bottom)
    entries = EntriesCollection(parser, text)

    return Timesheet(entries)
Exemple #9
0
def test_parse_continuation_entry_with_unknown_end_time():
    contents = """03.07.2017
alias_1       0845-0930 xxx
alias_1       -? xxx
"""
    lines = TimesheetParser().parse_text(contents)

    assert lines[-1].hours == 0
    assert lines[-1].ignored
Exemple #10
0
def test_stripping_not_empty():
    lines = TimesheetParser.parse("""

10.01.2013

foobar 0900-1000 baz

""")
    assert len(lines) == 3
Exemple #11
0
def test_get_entries_excluding_pushed_excludes_pushed():
    contents = """01.04.2013
foo 2 bar
= bar 0900-1000 bar
foo 1 bar"""
    entries = EntriesCollection(TimesheetParser(), contents)
    timesheet = Timesheet(entries)
    timesheet_entries = timesheet.entries.filter(pushed=False)

    assert len(list(timesheet_entries.values())[0]) == 2
Exemple #12
0
def test_parse_entry_with_description_starting_with_digits():
    contents = """01.01.13

foobar 0900-1000 1 hour of review
"""

    lines = TimesheetParser().parse_text(contents)

    assert lines[2].alias == 'foobar'
    assert lines[2].duration == (datetime.time(9), datetime.time(10))
    assert lines[2].description == '1 hour of review'
Exemple #13
0
def test_parse_entry_with_digits_in_description():
    contents = """01.01.13

foobar 0900-1000 Sprint 1 review
"""

    lines = TimesheetParser().parse_text(contents)

    assert lines[2].alias == 'foobar'
    assert lines[2].duration == (datetime.time(9), datetime.time(10))
    assert lines[2].description == 'Sprint 1 review'
Exemple #14
0
def test_stripping_empty():
    lines = TimesheetParser.parse("""

""")
    assert len(lines) == 0
Exemple #15
0
def test_parse_time_separator_without_timespan():
    with pytest.raises(ParseError):
        TimesheetParser.parse_time('-')
Exemple #16
0
def test_parse_time_hours_out_of_range():
    with pytest.raises(ParseError):
        TimesheetParser.parse_time('-2500')
Exemple #17
0
def test_parse_time_valid_timespan_without_start():
    assert TimesheetParser.parse_time('-10:15') == (None,
                                                    datetime.time(10, 15))
Exemple #18
0
def test_parse_time_valid_timespan_with_separators():
    assert TimesheetParser.parse_time('09:00-10:15') == (datetime.time(9, 0),
                                                         datetime.time(10, 15))
Exemple #19
0
def test_parse_time_valid_big_integer():
    assert TimesheetParser.parse_time('0900') == 900.0
Exemple #20
0
def test_parse_time_valid_decimal():
    assert TimesheetParser.parse_time('1.75') == 1.75
Exemple #21
0
def test_extract_date_yyyy_mm_dd():
    assert TimesheetParser.extract_date('2013/08/09') == datetime.date(2013, 8, 9)
Exemple #22
0
def test_detect_formatting_padded_time_and_alias():
    formatting = TimesheetParser.detect_formatting(
        'foobar  1500-1600    description'
    )
    assert formatting['width'] == (8, 13)
Exemple #23
0
def test_detect_formatting_padded_time():
    formatting = TimesheetParser.detect_formatting(
        'foobar 1500-1600    description'
    )
    assert formatting['width'][1] == 13
Exemple #24
0
def test_detect_formatting_padded_alias():
    formatting = TimesheetParser.detect_formatting('foobar   4 description')
    assert formatting['width'][0] == 9
Exemple #25
0
def test_extract_date_short_year():
    assert TimesheetParser.extract_date('05/08/12') == datetime.date(2012, 8, 5)
Exemple #26
0
def test_extract_date_missing_all_separators():
    with pytest.raises(ValueError):
        assert TimesheetParser.extract_date('05082012')
Exemple #27
0
def test_extract_date_yyyy_mm_dd_missing_separator():
    with pytest.raises(ValueError):
        assert TimesheetParser.extract_date('2012/0801')
Exemple #28
0
def test_detect_formatting_time_format_separator():
    formatting = TimesheetParser.detect_formatting(
        'foobar 15:00-16:00 description'
    )
    assert formatting['time_format'] == '%H:%M'
Exemple #29
0
def test_parse_time_valid_integer():
    assert TimesheetParser.parse_time('3') == 3.0
Exemple #30
0
def test_formatting_space():
    formatting = TimesheetParser.detect_formatting('foobar 4 description')
    assert formatting['spacer'] == (' ', ' ')
Exemple #31
0
def test_parse_time_valid_timespan():
    assert TimesheetParser.parse_time('0900-1015') == (datetime.time(9, 0),
                                                       datetime.time(10, 15))
Exemple #32
0
def test_detect_formatting_space_tabs():
    formatting = TimesheetParser.detect_formatting('foobar\t4 description')
    assert formatting['spacer'] == ('\t', ' ')
Exemple #33
0
def test_parse_time_valid_timespan_without_end():
    assert TimesheetParser.parse_time('09:00-?') == (datetime.time(9, 0), None)
Exemple #34
0
def test_parse_error_contains_line_number():
    try:
        TimesheetParser.parse("hello world")
    except ParseError as e:
        assert e.line_number == 1
Exemple #35
0
def test_parse_time_invalid_string():
    with pytest.raises(ParseError):
        TimesheetParser.parse_time('foo')
Exemple #36
0
def test_extract_date_invalid_string():
    with pytest.raises(ValueError):
        assert TimesheetParser.extract_date('foobar')
Exemple #37
0
def test_parse_time_minutes_out_of_range():
    with pytest.raises(ParseError):
        TimesheetParser.parse_time('-1061')
Exemple #38
0
def test_extract_date_incomplete_date():
    with pytest.raises(ValueError):
        assert TimesheetParser.extract_date('05/08')
Exemple #39
0
def test_detect_formatting_time_hours():
    formatting = TimesheetParser.detect_formatting('foobar 4 description')
    assert formatting['time_format'] == '%H%M'
Exemple #40
0
def test_empty():
    assert len(TimesheetParser.parse('')) == 0