Exemplo n.º 1
0
def test_interval_should_be_hashable():
    a = TimeWarriorInterval(1, "20180816T100209Z", "20180816T110209Z", [],
                            None)
    b = TimeWarriorInterval(2, "20180816T090319Z", "20180816T100700Z", [],
                            None)

    assert {a, b}
Exemplo n.º 2
0
def test_parser_should_parse_intervals(export_with_intervals):
    parser = TimeWarriorParser(export_with_intervals.open('r'))

    intervals = parser.get_intervals()
    expected = [
        TimeWarriorInterval(
            '20160405T160000Z', '20160405T161000Z',
            ['This is a multi-word tag', 'ProjectA', 'tag123']),
        TimeWarriorInterval(
            '20160405T161000Z', '20160405T162000Z',
            ['This is a multi-word tag', 'ProjectA', 'tag123']),
        TimeWarriorInterval(
            '20160405T162000Z', '20160405T163000Z',
            ['This is a multi-word tag', 'ProjectA', 'tag123']),
    ]
    assert (intervals == expected)
Exemplo n.º 3
0
def test_parser_should_parse_interval_without_tags(export_with_interval_without_tags):
    parser = TimeWarriorParser(export_with_interval_without_tags.open('r'))

    intervals = parser.get_intervals()
    expected = [
        TimeWarriorInterval(1, '20160405T160000Z', '20160405T161000Z', [], None),
    ]
    assert (intervals == expected)
Exemplo n.º 4
0
def test_parser_should_parse_open_interval(export_with_open_interval):
    parser = TimeWarriorParser(export_with_open_interval.open('r'))

    intervals = parser.get_intervals()
    expected = [
        TimeWarriorInterval(1, '20160405T160000Z', None, ['This is a multi-word tag', 'ProjectA', 'tag123'], None),
    ]
    assert (intervals == expected)
Exemplo n.º 5
0
def give_interval(day=None, tags=[]):
    if day:
        start = day.replace(hour=randint(0, 12))
    else:
        start = datetime.today().replace(day=randint(1, 28), month=randint(1, 12))

    end = start + timedelta(0, randint(60 * 5, 60 * 60 * 2))  # up to 2h

    return TimeWarriorInterval(start.strftime(DT_FORMAT), end.strftime(DT_FORMAT), tags)
Exemplo n.º 6
0
def test_interval_should_be_creatable_from_local_datetime():
    test_start = datetime.now(tz=tz.tzlocal()).replace(microsecond=0)
    test_end = test_start + timedelta(hours=1)

    interval = TimeWarriorInterval(1, test_start, test_end, [], None)

    assert interval.get_start() == test_start \
           and interval.get_end() == test_end \
           and interval.get_start_date() == test_start.date() \
           and interval.get_end_date() == test_end.date()
Exemplo n.º 7
0
    def __parse_intervals_section(input_stream):
        json_string = ''

        for line in input_stream:
            json_string += line

        intervals = []

        for interval in json.loads(json_string):
            intervals.append(TimeWarriorInterval(
                interval['start'],
                interval['end'] if 'end' in interval else None,
                interval['tags'] if 'tags' in interval else []
            ))

        return intervals
Exemplo n.º 8
0
def test_interval_should_be_creatable_from_utc_string():
    test_start = datetime.now(tz=tz.tzlocal()).replace(microsecond=0)
    test_start_utc = test_start.utcnow()
    test_end = test_start + timedelta(hours=1)
    test_end_utc = test_start_utc + timedelta(hours=1)

    interval = TimeWarriorInterval(1,
                                   "{:%Y%m%dT%H%M%S}Z".format(test_start_utc),
                                   "{:%Y%m%dT%H%M%S}Z".format(test_end_utc),
                                   [], None)

    assert interval.get_start() == test_start \
           and interval.get_end() == test_end \
           and interval.get_start_date() == test_start.date() \
           and interval.get_end_date() == test_end.date()
Exemplo n.º 9
0
def test_interval_should_be_hashable():
    a = TimeWarriorInterval("20180816T100209Z", "20180816T110209Z", [])
    b = TimeWarriorInterval("20180816T090319Z", "20180816T100700Z", [])

    set([a, b])