def test_maintains_a_list_of_past_projects_in_reverse_order_of_opening(): history = ProjectHistory() history.project_opened(make_project(filename='oldest.tgit')) history.project_opened(make_project(filename='previous.tgit')) history.project_opened(make_project(filename='latest.tgit')) assert_that(history, contains(snapshot_with(path="latest.tgit"), snapshot_with(path="previous.tgit"), snapshot_with(path="oldest.tgit")), "past projects")
def test_maintains_a_list_of_past_projects_in_reverse_order_of_opening(): history = ProjectHistory() history.project_opened(make_project(filename='oldest.tgit')) history.project_opened(make_project(filename='previous.tgit')) history.project_opened(make_project(filename='latest.tgit')) assert_that( history, contains(snapshot_with(path="latest.tgit"), snapshot_with(path="previous.tgit"), snapshot_with(path="oldest.tgit")), "past projects")
def test_signals_when_project_created(studio, subscriber): new_project = make_project() subscriber.should_receive("project_opened").with_args(new_project).once() studio.on_project_opened.subscribe(subscriber.project_opened) studio.project_created(new_project)
def test_saves_project_to_catalog_and_then_reports_save_success_to_studio(studio, catalog): project_to_save = make_project() catalog.should_receive("save_project").with_args(project_to_save).once().ordered() studio.should_receive("project_saved").with_args(project_to_save).once().ordered() project.save_to(studio, catalog=catalog)(project_to_save)
def test_keeps_track_of_current_project(studio): current_project = make_project() studio.project_loaded(current_project) assert_that(studio.current_project, is_(current_project), "current project loaded") studio.project_closed(current_project) assert_that(studio.current_project, is_(none()), "current project closed")
def test_signals_when_project_closed(studio, subscriber): closed_project = make_project() subscriber.should_receive("project_closed").with_args(closed_project).once() studio.on_project_closed.subscribe(subscriber.project_closed) studio.project_closed(closed_project)
def test_saves_history_to_store_whenever_it_changes(studio, store): history = make_project_history() store.should_receive("load_history").and_return(history) store.should_receive("store_history").with_args(matching(contains(snapshot_with(path="/new")))).once() history = load_from(studio, store) history.project_opened(make_project("/new"))
def test_signals_when_project_closed(studio, subscriber): closed_project = make_project() subscriber.should_receive("project_closed").with_args( closed_project).once() studio.on_project_closed.subscribe(subscriber.project_closed) studio.project_closed(closed_project)
def test_loads_project_from_catalog_and_then_reports_load_success_to_studio( studio, catalog): project_to_load = make_project() catalog.should_receive("load_project").with_args( "/path/to/project.tgit").and_return(project_to_load) studio.should_receive("project_loaded").with_args(project_to_load).once() project.load_to(studio, from_catalog=catalog)(filename="/path/to/project.tgit")
def test_updates_history_and_reports_history_change_when_project_changes(subscriber): history = ProjectHistory(make_snapshot(path="updated.tgit", name="original")) subscriber.should_receive("history_changed").once() history.on_history_changed.subscribe(subscriber.history_changed) history.project_opened(make_project(filename="updated.tgit", release_name="updated")) assert_that(history, contains(snapshot_with(path="updated.tgit", name="updated")), "updated project history")
def test_saves_history_to_store_whenever_it_changes(studio, store): history = make_project_history() store.should_receive("load_history").and_return(history) store.should_receive("store_history").with_args( matching(contains(snapshot_with(path="/new")))).once() history = load_from(studio, store) history.project_opened(make_project("/new"))
def test_limits_history_to_last_10_entries(): history = ProjectHistory() for index in range(15): history.project_opened(make_project(filename=str(index))) assert_that( history, contains(*(snapshot_with(path=str(index)) for index in reversed(range(5, 15)))))
def test_reorders_history_to_reflect_latest_updates(): history = ProjectHistory(make_snapshot(path="1.tgit"), make_snapshot(path="2.tgit"), make_snapshot(path="3.tgit")) history.project_saved(make_project(filename="2.tgit")) assert_that(history, contains(snapshot_with(path="2.tgit"), snapshot_with(path="1.tgit"), snapshot_with(path="3.tgit")), "updated project history")
def test_snapshots_thumbnail_of_project_main_cover(scaler): project = make_project(images=[make_image(mime="image/png", data=b'<image data>')]) scaler.should_receive("scale").with_args( matching(image_with(mime="image/png", data=b'<image data>')), 64, 64).and_return( Image(mime="image/png", data=b'<scaled image data>')) snapshot = ProjectSnapshot.of(project, image_editor=scaler) project.remove_images() assert_that(snapshot.cover_art, image_with(mime="image/png", data=b'<scaled image data>'), "snapshot's thumbnail")
def test_reorders_history_to_reflect_latest_updates(): history = ProjectHistory(make_snapshot(path="1.tgit"), make_snapshot(path="2.tgit"), make_snapshot(path="3.tgit")) history.project_saved(make_project(filename="2.tgit")) assert_that( history, contains(snapshot_with(path="2.tgit"), snapshot_with(path="1.tgit"), snapshot_with(path="3.tgit")), "updated project history")
def test_snapshots_thumbnail_of_project_main_cover(scaler): project = make_project( images=[make_image(mime="image/png", data=b'<image data>')]) scaler.should_receive("scale").with_args( matching(image_with(mime="image/png", data=b'<image data>')), 64, 64).and_return(Image(mime="image/png", data=b'<scaled image data>')) snapshot = ProjectSnapshot.of(project, image_editor=scaler) project.remove_images() assert_that(snapshot.cover_art, image_with(mime="image/png", data=b'<scaled image data>'), "snapshot's thumbnail")
def test_updates_history_and_reports_history_change_when_project_changes( subscriber): history = ProjectHistory( make_snapshot(path="updated.tgit", name="original")) subscriber.should_receive("history_changed").once() history.on_history_changed.subscribe(subscriber.history_changed) history.project_opened( make_project(filename="updated.tgit", release_name="updated")) assert_that(history, contains(snapshot_with(path="updated.tgit", name="updated")), "updated project history")
def test_snapshots_project_type(): project = make_project(type_="flac") snapshot = ProjectSnapshot.of(project) project.type = "mp3" assert_that(snapshot.type, equal_to("flac"), "snapshot's type")
def test_limits_history_to_last_10_entries(): history = ProjectHistory() for index in range(15): history.project_opened(make_project(filename=str(index))) assert_that(history, contains(*(snapshot_with(path=str(index)) for index in reversed(range(5, 15)))))
def test_loads_project_from_catalog_and_then_reports_load_success_to_studio(studio, catalog): project_to_load = make_project() catalog.should_receive("load_project").with_args("/path/to/project.tgit").and_return(project_to_load) studio.should_receive("project_loaded").with_args(project_to_load).once() project.load_to(studio, from_catalog=catalog)(filename="/path/to/project.tgit")
def test_snapshots_project_name(): project = make_project(release_name="Original") snapshot = ProjectSnapshot.of(project) project.release_name = "Updated" assert_that(snapshot.name, equal_to("Original"), "snapshot's name")
def test_snapshots_project_filename(): project = make_project(filename="project.tgit") snapshot = ProjectSnapshot.of(project) assert_that(snapshot.path, equal_to("project.tgit"), "snapshot's path")