Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Playback times #196

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools
import sys
from pathlib import Path
from typing import Literal

import pytest
from PyQt6.QtWidgets import QApplication
Expand All @@ -24,6 +23,7 @@
from tilia.ui.qtui import QtUI, TiliaMainWindow
from tilia.ui.cli.ui import CLI
from tilia.ui.windows import WindowKind
from tilia.ui.dialogs.scale_or_crop import ScaleOrCrop
from tilia.requests.get import reset as reset_get
from tilia.requests.post import reset as reset_post

Expand Down Expand Up @@ -99,7 +99,11 @@ def duration(self):
def duration(self, value):
self.app.set_file_media_duration(value)

def set_duration(self, value, scale_timelines: Literal['yes', 'no', 'prompt'] = 'prompt'):
def set_duration(
self,
value,
scale_timelines: ScaleOrCrop.ActionToTake = ScaleOrCrop.ActionToTake.PROMPT,
):
"""Use this if you want to pass scale_timelines."""
self.app.set_file_media_duration(value, scale_timelines)

Expand Down Expand Up @@ -200,7 +204,7 @@ def add_timeline_with_post(kind: TimelineKind, name: str = ""):
TimelineKind.HIERARCHY_TIMELINE: Post.TIMELINE_ADD_HIERARCHY_TIMELINE,
TimelineKind.HARMONY_TIMELINE: Post.TIMELINE_ADD_HARMONY_TIMELINE,
TimelineKind.BEAT_TIMELINE: Post.TIMELINE_ADD_BEAT_TIMELINE,
TimelineKind.AUDIOWAVE_TIMELINE: Post.TIMELINE_ADD_AUDIOWAVE_TIMELINE
TimelineKind.AUDIOWAVE_TIMELINE: Post.TIMELINE_ADD_AUDIOWAVE_TIMELINE,
}
with Serve(Get.FROM_USER_STRING, (name, True)):
post(kind_to_request[kind])
Expand All @@ -219,14 +223,15 @@ def tlui(request, marker_tlui, harmony_tlui, beat_tlui, hierarchy_tlui, audiowav
"harmony": harmony_tlui,
"beat": beat_tlui,
"hierarchy": hierarchy_tlui,
"audiowave": audiowave_tlui
"audiowave": audiowave_tlui,
}[request.param]


class UserActionManager:
"""
Class to simulate and mock user interaction with the GUI.
"""

def __init__(self):
self.action_to_trigger_count = {}
for action in tilia_actions_module.TiliaAction:
Expand Down
35 changes: 27 additions & 8 deletions tests/file/test_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from pathlib import Path
from unittest.mock import mock_open
import pytest
from tests.mock import PatchPost, PatchGet, PatchGetMultiple, Serve
from tests.mock import PatchPost, PatchGet, Serve
from tilia.file.media_metadata import MediaMetadata

import tests.utils
from tilia.requests import Post, post, stop_listening_to_all, stop_serving_all, Get
from tilia.file.tilia_file import TiliaFile
from tilia.file.file_manager import FileManager
from unittest.mock import patch
from tilia.ui.windows.metadata import MediaMetadataWindow

from tilia.ui.actions import TiliaAction

Expand Down Expand Up @@ -93,27 +94,45 @@ def test_file_not_modified_after_open(self, tilia):
assert not tilia.file_manager.is_file_modified(tilia.file_manager.file.__dict__)

def test_metadata_edit_fields(self, tilia):
original = list(tilia.file_manager.file.media_metadata)
fields = list(tilia.file_manager.file.media_metadata)
def get_displayed_list(input: list[str]) -> list[str]:
output = []
for item in input:
if (
item
not in MediaMetadataWindow.SEPARATE_WINDOW_FIELDS
+ list(MediaMetadataWindow.READ_ONLY_FIELDS)
+ MediaMetadataWindow.PLAYBACK_TIMES
):
output.append(item)
return output

original = get_displayed_list(tilia.file_manager.file.media_metadata)
fields = get_displayed_list(tilia.file_manager.file.media_metadata)
fields.insert(2, "newfield")
post(Post.METADATA_UPDATE_FIELDS, fields)
assert list(tilia.file_manager.file.media_metadata)[2] == "newfield"
assert (
get_displayed_list(tilia.file_manager.file.media_metadata)[2] == "newfield"
)

fields.pop(2)
post(Post.METADATA_UPDATE_FIELDS, fields)
assert list(tilia.file_manager.file.media_metadata)[2] != "newfield"
assert list(tilia.file_manager.file.media_metadata) == original
assert (
get_displayed_list(tilia.file_manager.file.media_metadata)[2] != "newfield"
)
assert get_displayed_list(tilia.file_manager.file.media_metadata) == original

def test_metadata_not_duplicated_required_fields(self, tilia):
original = list(tilia.file_manager.file.media_metadata)
duplicate = list(tilia.file_manager.file.media_metadata) + ["title"]
post(Post.METADATA_UPDATE_FIELDS, duplicate)
assert list(tilia.file_manager.file.media_metadata) == original

def test_metadata_delete_fields(self, tilia):
empty_list = []
post(Post.METADATA_UPDATE_FIELDS, empty_list)
assert list(tilia.file_manager.file.media_metadata) == list(tilia.file_manager.file.media_metadata.REQUIRED_FIELDS)
assert list(tilia.file_manager.file.media_metadata) == list(
tilia.file_manager.file.media_metadata.REQUIRED_FIELDS
)

def test_metadata_title_stays_on_top(self, tilia):
not_so_empty_list = ["newfield"]
Expand Down
Loading