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_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 #3
0
def test_stripping_not_empty():
    lines = TimesheetParser.parse("""

10.01.2013

foobar 0900-1000 baz

""")
    assert len(lines) == 3
Exemple #4
0
def test_parse_error_contains_line_number():
    try:
        TimesheetParser.parse("hello world")
    except ParseError as e:
        assert e.line_number == 1
Exemple #5
0
def test_stripping_empty():
    lines = TimesheetParser.parse("""

""")
    assert len(lines) == 0
Exemple #6
0
def test_empty():
    assert len(TimesheetParser.parse('')) == 0
Exemple #7
0
def test_invalid_line():
    content = """10.01.2013
foobar 0900-1000 baz
foo"""
    with pytest.raises(ParseError):
        TimesheetParser.parse(content)
Exemple #8
0
def test_invalid_date():
    with pytest.raises(ParseError):
        TimesheetParser.parse("1110.2013")
        TimesheetParser.parse("11102013")