Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-photo

Source of release 0.1.0

0.1.0 / tests / folders / main.luc

## Library folders on a fresh library in HOME: folders in folders; the sample
## raws (luce-raw's, skipped when they are not there) imported into the inner
## one; counts take in subfolders; photos move between folders; deleting a
## folder hands its photos and folders to the folder it was in. Prints PASS or
## traps.
from photo_library import PhotoLibrary
from folder_tree import trash
from luce_std import files, paths, clock


func expect(condition: bool, what: str) -> unit!:
    if not condition:
        print(f"FAIL folders: {what}")
        trap(what)

pub func main(arguments: list[str]) -> int!:
    let samples = ["../luce-raw/build/samples/leica_m240.dng", "../luce-raw/build/samples/fuji_xt2_xtrans_14c.raf"]
    for sample in samples:
        if not files.exists(sample):
            print("skip: no sample raws in ../luce-raw/build/samples (luce-raw/tests/run.py fetches them)")
            return 0
    let library = PhotoLibrary(paths.join(files.home_directory(), "Folders.library"))
    let trips = library.make_folder("Trips", 0)
    let lisbon = library.make_folder("Lisbon", trips)
    let family = library.make_folder("Family", 0)
    expect(library.folders.count() == 3 and library.folders.within(lisbon, trips) and not library.folders.within(trips, lisbon), "folders hold folders")
    expect(not library.move_folder(trips, lisbon), "a folder does not go inside its own folder")
    library.show_folder(lisbon)
    library.start_import(samples)
    while library.importing():
        clock.sleep(0.05)
    _ = library.poll_import()
    library.reload()
    expect(library.count_in(lisbon) == 2 and library.count_in(trips) == 2 and library.count_in(family) == 0, "the import went into Lisbon, counted in Trips")
    library.show_folder(trips)
    expect(library.index.count() == 2, "Trips shows its subfolder's photos")
    library.show_folder(lisbon)
    library.move_photos([0], family)
    expect(library.count_in(family) == 1 and library.count_in(lisbon) == 1, "a photo moved to Family")
    library.rename_folder(family, "Home")
    expect(library.folders.name(library.folders.position_of(family)) == "Home", "a folder renamed")
    library.delete_folder(trips)
    let at = library.folders.position_of(lisbon)
    expect(library.folders.position_of(trips) < 0 and at >= 0 and library.folders.parent(at) == 0, "Lisbon went up when Trips was deleted")
    expect(library.count_in(lisbon) == 1 and library.count_in(0) == 2, "no photo was lost")
    # The Trash: a photo moved in leaves All Photos; put back, it returns;
    # emptied, its original and its cached pictures are gone.
    library.show_folder(0)
    let doomed = library.original_path(0)
    let id = library.index.id(0)
    library.trash_photos([0])
    expect(library.count_in(0) == 1 and library.count_in(trash) == 1 and library.index.count() == 1, "a photo went to the Trash")
    library.show_folder(trash)
    expect(library.index.count() == 1 and library.index.id(0) == id, "the Trash shows it")
    library.put_back([0])
    expect(library.count_in(trash) == 0 and library.count_in(0) == 2, "put back")
    library.show_folder(0)
    library.trash_photos([library.index.position_of(id)])
    expect(files.exists(doomed) and files.exists(library.thumb_path(id)), "its files are there before emptying")
    expect(library.empty_trash() == 1, "the Trash emptied one photo")
    expect(not files.exists(doomed) and not files.exists(library.thumb_path(id)), "its original and thumbnail are deleted")
    expect(library.count_in(trash) == 0 and library.count_in(0) == 1 and library.index.position_of(id) < 0, "and its row")
    library.close()
    print("PASS folders: nested, imported into, counted, moved, renamed, deleted, trashed, put back and emptied")
    return 0