Ejemplo n.º 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_text(content)

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

    lines = TimesheetParser().parse_text(content)
    assert len(lines) == 3
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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'
Ejemplo n.º 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'
Ejemplo n.º 6
0
def test_detect_formatting_no_alias_padding():
    line = Entry(
        'foobar',
        4,
        'description',
    )
    assert TimesheetParser().entry_line_to_text(line) == 'foobar 4 description'
Ejemplo n.º 7
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_text(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], Entry)
    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], Entry)
    assert lines[7].duration == (datetime.time(10, 0), None)
    assert isinstance(lines[8], Entry)
    assert lines[8].alias == 'foo'
    assert lines[8].ignored
Ejemplo n.º 8
0
def test_stripping_not_empty():
    lines = TimesheetParser().parse_text("""

10.01.2013

foobar 0900-1000 baz

""")
    assert len(lines) == 3
Ejemplo n.º 9
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)
Ejemplo n.º 10
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
Ejemplo n.º 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
Ejemplo n.º 12
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'
Ejemplo n.º 13
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'
Ejemplo n.º 14
0
def test_extract_date_dot_separator():
    assert TimesheetParser().create_date_from_text(
        '1.1.2010') == datetime.date(2010, 1, 1)
Ejemplo n.º 15
0
def test_extract_date_short_year():
    assert TimesheetParser().create_date_from_text(
        '05/08/12') == datetime.date(2012, 8, 5)
Ejemplo n.º 16
0
def test_extract_date_yyyy_mm_dd_missing_separator():
    with pytest.raises(ValueError):
        assert TimesheetParser().create_date_from_text('2012/0801')
Ejemplo n.º 17
0
def test_extract_date_missing_all_separators():
    with pytest.raises(ValueError):
        assert TimesheetParser().create_date_from_text('05082012')
Ejemplo n.º 18
0
def test_extract_date_incomplete_date():
    with pytest.raises(ValueError):
        assert TimesheetParser().create_date_from_text('05/08')
Ejemplo n.º 19
0
def test_inexistent_flag_raises_parse_error():
    with pytest.raises(ParseError):
        TimesheetParser().create_entry_line_from_text(
            '^ foo 09:00-10:15 Description')
Ejemplo n.º 20
0
def test_stripping_empty():
    lines = TimesheetParser().parse_text("""

""")
    assert len(lines) == 0
Ejemplo n.º 21
0
def test_parse_time_valid_timespan_without_end():
    t = TimesheetParser().create_entry_line_from_text(
        'foo 09:00-? Description')
    assert t.duration == (datetime.time(9, 0), None)
Ejemplo n.º 22
0
def test_extract_date_invalid_string():
    with pytest.raises(ValueError):
        assert TimesheetParser().create_date_from_text('foobar')
Ejemplo n.º 23
0
def test_empty():
    assert len(TimesheetParser().parse_text('')) == 0
Ejemplo n.º 24
0
def test_entry_with_flag_keeps_flag():
    t = TimesheetParser().create_entry_line_from_text(
        '= foo 09:00-10:15 Description')
    assert Entry.FLAG_PUSHED in t.flags
Ejemplo n.º 25
0
def test_extract_date_yyyy_mm_dd():
    assert TimesheetParser().create_date_from_text(
        '2013/08/09') == datetime.date(2013, 8, 9)
Ejemplo n.º 26
0
def test_invalid_date(date):
    with pytest.raises(ParseError):
        TimesheetParser().parse_text(date)
Ejemplo n.º 27
0
def test_invalid_line():
    content = """10.01.2013
foobar 0900-1000 baz
foo"""
    with pytest.raises(ParseError):
        TimesheetParser().parse_text(content)
Ejemplo n.º 28
0
def test_parse_time_valid_timespan_with_separators():
    t = TimesheetParser().create_entry_line_from_text(
        'foo 09:00-10:15 Description')
    assert t.duration == (datetime.time(9, 0), datetime.time(10, 15))
Ejemplo n.º 29
0
def test_parse_error_contains_line_number():
    try:
        TimesheetParser().parse_text("hello world")
    except ParseError as e:
        assert e.line_number == 1
Ejemplo n.º 30
0
def test_parse_time_valid_timespan_without_start():
    t = TimesheetParser().create_entry_line_from_text('foo -10:15 Description')
    assert t.duration == (None, datetime.time(10, 15))