예제 #1
0
파일: test_parser.py 프로젝트: sephii/taxi
def test_detect_formatting_padded_time_and_alias():
    line = Entry(
        'foobar', (datetime.time(15, 0), datetime.time(16, 0)), 'description',
        text=('', '', 'foobar', '   ', '1500-1600', '   ', 'description')
    )
    line.duration = (datetime.time(14, 0), datetime.time(15, 0))
    assert TimesheetParser().entry_line_to_text(line) == 'foobar   14:00-15:00 description'
예제 #2
0
    def test_add(self):
        contents = """10.10.2012
foo 09:00-10:00 baz"""

        t = create_timesheet(contents)
        t.entries.parser.add_date_to_bottom = True
        e = Entry('bar', 2, 'baz')
        t.entries[datetime.date(2012, 10, 10)].append(e)
        e = Entry('bar', 2, 'baz')
        t.entries[datetime.date(2012, 10, 20)].append(e)
        entries = t.entries
        self.assertEquals(len(entries), 2)
        self.assertIn(datetime.date(2012, 10, 10), entries)
        self.assertIn(datetime.date(2012, 10, 20), entries)
        self.assertEquals(len(entries[datetime.date(2012, 10, 10)]), 2)
        self.assertEquals(len(entries[datetime.date(2012, 10, 20)]), 1)

        self.assertEquals(t.entries.to_lines(), [
            '10.10.2012', 'foo 09:00-10:00 baz', 'bar 2 baz', '', '20.10.2012',
            '', 'bar 2 baz'
        ])

        e = Entry('bar', 2, 'baz')
        t.entries.parser.add_date_to_bottom = False
        t.entries[datetime.date(2012, 10, 25)].append(e)

        self.assertEquals(t.entries.to_lines(), [
            '25.10.2012', '', 'bar 2 baz', '', '10.10.2012',
            'foo 09:00-10:00 baz', 'bar 2 baz', '', '20.10.2012', '',
            'bar 2 baz'
        ])
예제 #3
0
파일: test_parser.py 프로젝트: gnutix/taxi
def test_detect_formatting_padded_time_and_alias():
    line = Entry('foobar', (datetime.time(15, 0), datetime.time(16, 0)),
                 'description',
                 text=('', '', 'foobar', '   ', '1500-1600', '   ',
                       'description'))
    line.duration = (datetime.time(14, 0), datetime.time(15, 0))
    assert TimesheetParser().entry_line_to_text(
        line) == 'foobar   14:00-15:00 description'
예제 #4
0
파일: test_parser.py 프로젝트: gnutix/taxi
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'
예제 #5
0
파일: test_parser.py 프로젝트: gnutix/taxi
def test_detect_formatting_no_alias_padding():
    line = Entry(
        'foobar',
        4,
        'description',
    )
    assert TimesheetParser().entry_line_to_text(line) == 'foobar 4 description'
예제 #6
0
    def test_add_empty_date(self):
        contents = """10.10.2012
"""
        t = create_timesheet(contents)
        e = Entry('bar', 2, 'baz')
        t.entries[datetime.date(2012, 10, 10)].append(e)

        self.assertEqual(t.entries.to_lines(), ['10.10.2012', '', 'bar 2 baz'])
예제 #7
0
    def test_add_entry_empty_end_time(self):
        t = create_timesheet('')
        now = datetime.datetime.now()

        entry = Entry('foo', (now.time(), None), 'bar')
        t.entries[now.date()].append(entry)

        lines = t.entries.to_lines()
        self.assertEquals(lines, ['13.10.2012', '', 'foo 00:00-? bar'])
예제 #8
0
def test_add_entry_to_entries_collection():
    entries_collection = EntriesCollection(
        TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine"
    )
    entries_collection[datetime.date(2014, 1, 20)].append(
        Entry('taxi', 4, 'Work a bit')
    )

    assert len(entries_collection[datetime.date(2014, 1, 20)]) == 2
예제 #9
0
def test_entry_with_undefined_alias_can_be_added():
    contents = """10.10.2012
foo 0900-1000 baz"""

    t = create_timesheet(contents)
    e = Entry('baz', (datetime.time(10, 0), None), 'baz')
    t.entries[datetime.date(2012, 10, 10)].append(e)

    lines = t.entries.to_lines()
    assert lines == [
        '10.10.2012', 'foo 0900-1000 baz', 'baz 10:00-? baz'
    ]
예제 #10
0
def test_insert_to_top():
    parser = TimesheetParser(add_date_to_bottom=False)
    entries_collection = EntriesCollection(parser, """20.01.2014
_internal 0800-0900 Fix coffee machine""")

    entries_date = datetime.date(2014, 1, 21)
    entry_line = Entry('taxi', 4, 'Work a bit')
    entries_collection[entries_date].append(entry_line)

    assert entries_collection.parser.to_text(entries_collection.lines[0]) == "21.01.2014"
    assert entries_collection.parser.to_text(entries_collection.lines[1]) == ""
    assert entries_collection.lines[2] == entry_line
예제 #11
0
    def test_add_empty_timesheet(self):
        t = create_timesheet('')
        today = datetime.date.today()

        entry = Entry('foo', 2, 'bar')
        t.entries[today].append(entry)

        entries = t.entries
        self.assertEquals(len(entries), 1)
        self.assertIn(today, entries)
        self.assertIsInstance(entries[today][0], Entry)
        self.assertEquals(entries[today][0].alias, 'foo')
        self.assertEquals(entries[today][0].duration, 2)
예제 #12
0
def test_to_lines_returns_appended_lines():
    contents = """10.10.2012
foo 09:00-10:00 baz
bar      -11:00 foobar"""

    t = create_timesheet(contents, True)
    t.entries[datetime.date(2012, 9, 29)].append(
        Entry('foo', (datetime.time(15, 0), None), 'bar'))
    lines = t.entries.to_lines()
    assert lines == [
        '10.10.2012', 'foo 09:00-10:00 baz', 'bar      -11:00 foobar', '',
        '29.09.2012', '', 'foo 15:00-? bar'
    ]
예제 #13
0
파일: test_parser.py 프로젝트: gnutix/taxi
def test_detect_formatting_no_time_padding():
    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'