Ejemplo n.º 1
0
def test_add_lights_on_mark_correct():
    dest_label = "Lights On"
    with open(TEST_RES + "/realisticLogs/lights_on.txt", "r") as file:
        source = Log.from_file(file)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        middle = Log.from_file(file)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        destination = RawLog.from_file(file)

    frame_diff = 54001 + 54001 - 12331 + 54001
    # pylint: disable=bad-continuation
    time_diff = timedelta(minutes=30, seconds=0.03) + \
                timedelta(minutes=30, seconds=0.03) - \
                timedelta(minutes=6, seconds=51.03) + \
                timedelta(minutes=30, seconds=0.03)
    with open(TEST_RES + "/realisticLogs/all.txt", "r") as file:
        expected = RawLog.from_file(file)
    new_mark = Mark(-frame_diff, -time_diff, dest_label)
    expected.marks.append(new_mark.to_line_tab())

    actual = copy_mark_disjoint([source, middle, middle], "Lights On",
                                destination, dest_label)

    assert expected.marks == actual.marks
    assert "-" in expected.marks[-1]
Ejemplo n.º 2
0
def copy_mark(logs: List[Tuple[Log, timedelta, int]], src_pattern: str,
              dest: RawLog, dest_label: str) -> RawLog:
    """Copy a behavior into another log file as a mark, adjusting time and frame

    Time and frame are adjusted so as to be correct (potentially by being
    negative) in relation to the other entries in ``dest``. The logs are aligned
    in time using the provided start time and frame information.

    Args:
        logs: List of tuples containing log to search for ``src_pattern`` in and
            account for when adjusting time and frame, time at which the next
            video (``dest`` for last video) starts, and frame at which the next
            video (``dest`` for last video) starts
        src_pattern: Search pattern (regular expression) that identifies the
            behavior to copy
        dest: Log to insert mark into
        dest_label: Label for inserted mark

    Returns:
        A copy of ``dest``, but with the new mark inserted

    """
    found = False
    frames = 0
    time = timedelta(seconds=0)
    for tup in logs:
        tup[0].sort_lists()

    for log, s_time, s_frame in logs:
        if not found:
            for behav in log.full:
                if re.match(src_pattern, behav.description):
                    found = True

                    frames = s_frame - behav.frame
                    time = s_time - behav.time
        else:
            frames += s_frame
            time += s_time

    new_mark = Mark(-frames, -time, dest_label)
    new_log = RawLog.from_raw_log(dest)
    new_log.marks.append(new_mark.to_line_tab())
    return new_log
Ejemplo n.º 3
0
def test_from_rawlog():
    str_full = " 0  00:00.00  null  either "
    str_mark = "    1     0:00.03    video start"

    rawlog = RawLog()
    rawlog.full.append(str_full)
    rawlog.marks.append(str_mark)

    log = Log.from_raw_log(rawlog)

    assert log.full == [BehaviorFull(" 0  00:00.00  null  either ")]
    assert log.marks == [Mark.from_line("    1     0:00.03    video start")]
Ejemplo n.º 4
0
def test_init_valid_start():
    mark = Mark(1, timedelta(seconds=0.03), "video start")
    assert mark.frame == 1
    assert mark.time == timedelta(seconds=0.03)
    assert mark.name == "video start"
Ejemplo n.º 5
0
def test_from_line_invalid_name():
    with pytest.raises(TypeError):
        Mark.from_line("    1     0:00.03    video start!")
Ejemplo n.º 6
0
def test_from_line_valid_time_negative():
    Mark.from_line("    1     -0:00.03    video start")
Ejemplo n.º 7
0
def test_from_line_invalid_time_one_middle_digit():
    with pytest.raises(TypeError):
        Mark.from_line("    1     0:0.03    video start")
Ejemplo n.º 8
0
def test_from_line_invalid_time_no_period():
    with pytest.raises(TypeError):
        Mark.from_line("    1     0:00:03    video start")
Ejemplo n.º 9
0
def test_to_line_valid_remove_leading_zero_hours():
    temp = " 54001    30:00.03    video end"
    mark = Mark(17, timedelta(seconds=3601.05), "weird mark")
    assert mark.to_line(temp) == "    17  1:00:01.05    weird mark"
Ejemplo n.º 10
0
def test_to_line_invalid_time_over_1_day():
    with pytest.raises(ValueError):
        mark = Mark(17, timedelta(days=1.05), "weird mark")
        mark.to_line(" 54001    30:00.03    video end")
Ejemplo n.º 11
0
def test_to_line_invalid_template_1_space_after_time():
    with pytest.raises(ValueError):
        mark = Mark(1, timedelta(seconds=1), "mark")
        mark.to_line("    1     0:00.03 video start")
Ejemplo n.º 12
0
def test_to_line_valid_long_frame_in_template():
    temp = "154001    30:00.03    video end"
    mark = Mark(17, timedelta(seconds=4.05), "weird mark")
    assert mark.to_line(temp) == "    17     0:04.05    weird mark"
Ejemplo n.º 13
0
def test_to_line_valid_one_word_name():
    temp = " 54001    30:00.03    video end"
    mark = Mark(17, timedelta(seconds=4.05), "mark")
    assert mark.to_line(temp) == "    17     0:04.05    mark"
Ejemplo n.º 14
0
def test_from_line_valid_start():
    mark = Mark.from_line("    1     0:00.03    video start")
    assert mark.frame == 1
    assert mark.time == timedelta(seconds=0.03)
    assert mark.name == "video start"
Ejemplo n.º 15
0
def test_to_line_valid_microsecs():
    temp = " 54001    30:00.03    video end"
    mark = Mark(17, timedelta(seconds=0.05), "weird mark")
    assert mark.to_line(temp) == "    17     0:00.05    weird mark"
Ejemplo n.º 16
0
def test_lt_equal():
    first = Mark.from_line("    1     0:00.03    A video starts")
    second = Mark.from_line("    1     0:00.03    A video starts")

    assert first >= second
Ejemplo n.º 17
0
def test_from_line_invalid_one_space_after_frame():
    with pytest.raises(TypeError):
        Mark.from_line("    1 0:00.03    video start")
Ejemplo n.º 18
0
def test_lt_frame_positive():
    first = Mark.from_line("    1     0:00.03    video start")
    second = Mark.from_line("    2     0:00.03    video start")

    assert first < second
Ejemplo n.º 19
0
def test_from_line_invalid_time_two_periods():
    with pytest.raises(TypeError):
        Mark.from_line("    1     0.00.03    video start")
Ejemplo n.º 20
0
def test_lt_frame_negative():
    first = Mark.from_line("    -2     0:00.03    video start")
    second = Mark.from_line("    -1     0:00.03    video start")

    assert first < second
Ejemplo n.º 21
0
def test_from_line_valid_negative_frame():
    Mark.from_line("    -1     0:00.03    video start")
Ejemplo n.º 22
0
def test_from_line_valid_end():
    mark = Mark.from_line("54001    30:00.03    video end")
    assert mark.frame == 54001
    assert mark.time == timedelta(seconds=1800.03)
    assert mark.name == "video end"
Ejemplo n.º 23
0
def test_from_line_invalid_time_nonnumeric():
    with pytest.raises(TypeError):
        Mark.from_line("    1     0:a00.03    video start")
Ejemplo n.º 24
0
def test_lt_time_negative():
    first = Mark.from_line("    1     -0:05.00    video start")
    second = Mark.from_line("    1     -0:00.03    video start")

    assert first < second
Ejemplo n.º 25
0
def test_from_line_valid_long_time():
    mark = Mark.from_line("    1     01:20:04.03    video start")
    assert mark.frame == 1
    assert mark.time == timedelta(seconds=(1 * 60 * 60 + 20 * 60 + 4.03))
    assert mark.name == "video start"
Ejemplo n.º 26
0
def test_lt_time_both_signs():
    first = Mark.from_line("    1     -0:00.03    video start")
    second = Mark.from_line("    1     0:00.03    video start")

    assert first < second
Ejemplo n.º 27
0
def test_init_valid_end():
    mark = Mark(54001, timedelta(seconds=(30 * 60 + 0.03)), "video end")
    assert mark.frame == 54001
    assert mark.time == timedelta(seconds=(30 * 60 + 0.03))
    assert mark.name == "video end"
Ejemplo n.º 28
0
def test_lt_name():
    first = Mark.from_line("    1     0:00.03    a video starts")
    second = Mark.from_line("    1     0:00.03    video start")

    assert first < second
Ejemplo n.º 29
0
def test_missing_start_mark():
    with pytest.raises(ValueError):
        get_ending_mark([Mark(0, timedelta(seconds=0), "foo")])
Ejemplo n.º 30
0
def test_lt_name_lexicographic():
    first = Mark.from_line("    1     0:00.03    A video starts")
    second = Mark.from_line("    1     0:00.03    video starts")

    assert first < second