mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-11 18:32:23 +08:00
nixosTests.lomiri-gallery-app: Optimise OCR
- Generate image & video data once, ahead of time - Use wait_for_console_text to detect when we're close to displaying text - Programmatically generate per-image-format tests - Switch to fullscreen for better OCR success odds
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
imageDataDir = "gallery-app-sampledata";
|
||||
imageLabel = "Image";
|
||||
in
|
||||
{
|
||||
name = "lomiri-gallery-app-standalone";
|
||||
meta.maintainers = lib.teams.lomiri.members;
|
||||
@@ -11,11 +15,38 @@
|
||||
services.xserver.enable = true;
|
||||
|
||||
environment = {
|
||||
etc."${imageDataDir}".source =
|
||||
pkgs.runCommand imageDataDir
|
||||
{
|
||||
nativeBuildInputs = with pkgs; [
|
||||
ffmpeg # make a video from the image
|
||||
(imagemagick.override { ghostscriptSupport = true; }) # add label for OCR
|
||||
];
|
||||
}
|
||||
''
|
||||
mkdir -p $out/{Pictures,Videos}
|
||||
|
||||
# Setup example data, OCR-friendly:
|
||||
# - White square, black text
|
||||
# - Small text for display OCR
|
||||
# - Big text for gallery preview OCR
|
||||
# - uppercase extension
|
||||
magick -size 500x500 -background white -fill black canvas:white \
|
||||
-pointsize 20 -annotate +100+100 '${imageLabel}' \
|
||||
-pointsize 70 -annotate +100+300 '${imageLabel}' \
|
||||
$out/Pictures/output.PNG
|
||||
|
||||
# Different image formats
|
||||
magick $out/Pictures/output.PNG $out/Pictures/output.JPG
|
||||
magick $out/Pictures/output.PNG $out/Pictures/output.BMP
|
||||
magick $out/Pictures/output.PNG $out/Pictures/output.GIF
|
||||
|
||||
# Video for dispatching
|
||||
ffmpeg -loop 1 -r 1 -i $out/Pictures/output.PNG -t 100 -pix_fmt yuv420p $out/Videos/output.MP4
|
||||
'';
|
||||
systemPackages =
|
||||
with pkgs;
|
||||
[
|
||||
ffmpeg # make a video from the image
|
||||
(imagemagick.override { ghostscriptSupport = true; }) # example image creation
|
||||
mpv # URI dispatching for video support
|
||||
xdotool # mouse movement
|
||||
]
|
||||
@@ -42,44 +73,30 @@
|
||||
enableOCR = true;
|
||||
|
||||
testScript =
|
||||
let
|
||||
imageLabel = "Image";
|
||||
in
|
||||
''
|
||||
machine.wait_for_x()
|
||||
|
||||
with subtest("lomiri gallery launches"):
|
||||
machine.succeed("lomiri-gallery-app >&2 &")
|
||||
machine.sleep(2)
|
||||
machine.wait_for_console_text("qq= AlbumsOverview") # logged when album page actually gets loaded
|
||||
machine.sleep(10)
|
||||
machine.send_key("alt-f10")
|
||||
machine.sleep(5)
|
||||
machine.wait_for_text(r"(Albums|Events|Photos)")
|
||||
machine.screenshot("lomiri-gallery_open")
|
||||
|
||||
machine.succeed("pkill -f lomiri-gallery-app")
|
||||
machine.succeed("pgrep -afx lomiri-gallery-app >&2")
|
||||
machine.succeed("pkill -efx lomiri-gallery-app >&2")
|
||||
machine.wait_until_fails("pgrep -afx lomiri-gallery-app >&2")
|
||||
|
||||
machine.succeed("mkdir /root/Pictures /root/Videos")
|
||||
# Setup example data, OCR-friendly:
|
||||
# - White square, black text
|
||||
# - Small text for display OCR
|
||||
# - Big text for gallery preview OCR
|
||||
# - uppercase extension
|
||||
machine.succeed(
|
||||
"magick -size 500x500 -background white -fill black canvas:white "
|
||||
+ "-pointsize 20 -annotate +100+100 '${imageLabel}' "
|
||||
+ "-pointsize 50 -annotate +100+300 '${imageLabel}' "
|
||||
+ "/root/Pictures/output.PNG"
|
||||
)
|
||||
machine.succeed("cp -vr /etc/${imageDataDir}/* /root")
|
||||
|
||||
# Different image formats
|
||||
machine.succeed("magick /root/Pictures/output.PNG /root/Pictures/output.JPG")
|
||||
machine.succeed("magick /root/Pictures/output.PNG /root/Pictures/output.BMP")
|
||||
machine.succeed("magick /root/Pictures/output.PNG /root/Pictures/output.GIF")
|
||||
|
||||
# Video for dispatching
|
||||
machine.succeed("ffmpeg -loop 1 -r 1 -i /root/Pictures/output.PNG -t 100 -pix_fmt yuv420p /root/Videos/output.MP4")
|
||||
|
||||
with subtest("lomiri gallery handles files"):
|
||||
with subtest("lomiri gallery finds files"):
|
||||
machine.succeed("lomiri-gallery-app >&2 &")
|
||||
machine.sleep(2)
|
||||
machine.wait_for_console_text("qq= AlbumsOverview") # logged when album page actually gets loaded
|
||||
machine.sleep(10)
|
||||
machine.send_key("alt-f10")
|
||||
machine.sleep(5)
|
||||
machine.wait_for_text(r"(Albums|Events|Photos|${imageLabel})")
|
||||
|
||||
machine.succeed("xdotool mousemove 30 40 click 1") # burger menu for categories
|
||||
@@ -89,74 +106,79 @@
|
||||
machine.wait_for_text("${imageLabel}") # should see thumbnail of at least one of them
|
||||
machine.screenshot("lomiri-gallery_photos")
|
||||
|
||||
machine.succeed("xdotool mousemove 80 140 click 1") # select newest one
|
||||
machine.sleep(2)
|
||||
machine.succeed("xdotool mousemove 80 140 click 1") # enable top-bar
|
||||
machine.succeed("xdotool mousemove 80 140 click 1") # select newest one
|
||||
machine.sleep(2)
|
||||
machine.succeed("xdotool mousemove 80 140 click 1") # enable top-bar
|
||||
machine.sleep(2)
|
||||
|
||||
# MP4 gets special treatment
|
||||
with subtest("lomiri gallery handles mp4"):
|
||||
machine.succeed("xdotool mousemove 935 40 click 1") # open media information
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("MP4") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_mp4_info")
|
||||
machine.send_key("esc")
|
||||
|
||||
with subtest("lomiri gallery handles mp4"):
|
||||
machine.succeed("xdotool mousemove 870 50 click 1") # open media information
|
||||
machine.wait_for_text("${imageLabel}") # make sure thumbnail processing worked
|
||||
|
||||
machine.succeed("xdotool mousemove 510 380 click 1") # dispatch to system's video handler
|
||||
machine.wait_until_succeeds("pgrep -u root -f mpv") # wait for video to start
|
||||
machine.sleep(10)
|
||||
machine.succeed("pgrep -u root -f mpv") # should still be playing
|
||||
machine.screenshot("lomiri-gallery_mp4_dispatch")
|
||||
|
||||
machine.send_key("q")
|
||||
machine.wait_until_fails("pgrep mpv") # wait for video to stop
|
||||
|
||||
machine.send_key("right")
|
||||
''
|
||||
+
|
||||
lib.concatMapStringsSep
|
||||
''
|
||||
machine.send_key("right")
|
||||
''
|
||||
(format: ''
|
||||
with subtest("lomiri gallery handles ${format.ext}"):
|
||||
machine.succeed("xdotool mousemove ${
|
||||
if format.buttonIsOffset then "900" else "940"
|
||||
} 50 click 1") # open media information
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("MP4") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_mp4_info")
|
||||
machine.wait_for_text("${format.ext}") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_${format.ext}_info")
|
||||
machine.send_key("esc")
|
||||
|
||||
machine.wait_for_text("${imageLabel}") # make sure thumbnail rendering worked
|
||||
|
||||
machine.succeed("xdotool mousemove 450 350 click 1") # dispatch to system's video handler
|
||||
machine.wait_until_succeeds("pgrep -u root -f mpv") # wait for video to start
|
||||
machine.sleep(10)
|
||||
machine.succeed("pgrep -u root -f mpv") # should still be playing
|
||||
machine.screenshot("lomiri-gallery_mp4_dispatch")
|
||||
|
||||
machine.send_key("q")
|
||||
machine.wait_until_fails("pgrep mpv") # wait for video to stop
|
||||
|
||||
machine.send_key("right")
|
||||
|
||||
with subtest("lomiri gallery handles gif"):
|
||||
machine.succeed("xdotool mousemove 870 50 click 1") # open media information
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("GIF") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_gif_info")
|
||||
machine.send_key("esc")
|
||||
|
||||
machine.wait_for_text("${imageLabel}") # make sure media shows fine
|
||||
machine.send_key("right")
|
||||
'')
|
||||
[
|
||||
{
|
||||
ext = "GIF";
|
||||
buttonIsOffset = false;
|
||||
}
|
||||
{
|
||||
ext = "BMP";
|
||||
buttonIsOffset = true;
|
||||
}
|
||||
{
|
||||
ext = "JPG";
|
||||
buttonIsOffset = true;
|
||||
}
|
||||
{
|
||||
ext = "PNG";
|
||||
buttonIsOffset = true;
|
||||
}
|
||||
]
|
||||
+ ''
|
||||
|
||||
with subtest("lomiri gallery handles bmp"):
|
||||
machine.succeed("xdotool mousemove 840 50 click 1") # open media information (extra icon, different location)
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("BMP") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_bmp_info")
|
||||
machine.send_key("esc")
|
||||
machine.succeed("pgrep -afx lomiri-gallery-app >&2")
|
||||
machine.succeed("pkill -efx lomiri-gallery-app >&2")
|
||||
machine.wait_until_fails("pgrep -afx lomiri-gallery-app >&2")
|
||||
|
||||
machine.wait_for_text("${imageLabel}") # make sure media shows fine
|
||||
machine.send_key("right")
|
||||
|
||||
with subtest("lomiri gallery handles jpg"):
|
||||
machine.succeed("xdotool mousemove 840 50 click 1") # open media information (extra icon, different location)
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("JPG") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_jpg_info")
|
||||
machine.send_key("esc")
|
||||
|
||||
machine.wait_for_text("${imageLabel}") # make sure media shows fine
|
||||
machine.send_key("right")
|
||||
|
||||
with subtest("lomiri gallery handles png"):
|
||||
machine.succeed("xdotool mousemove 840 50 click 1") # open media information (extra icon, different location)
|
||||
machine.sleep(2)
|
||||
machine.wait_for_text("PNG") # make sure we're looking at the right file
|
||||
machine.screenshot("lomiri-gallery_png_info")
|
||||
machine.send_key("esc")
|
||||
|
||||
machine.wait_for_text("${imageLabel}") # make sure media shows fine
|
||||
|
||||
machine.succeed("pkill -f lomiri-gallery-app")
|
||||
|
||||
with subtest("lomiri gallery localisation works"):
|
||||
machine.succeed("env LANG=de_DE.UTF-8 lomiri-gallery-app >&2 &")
|
||||
machine.wait_for_console_text("qq= AlbumsOverview") # logged when album page actually gets loaded
|
||||
machine.sleep(10)
|
||||
machine.send_key("alt-f10")
|
||||
machine.sleep(5)
|
||||
machine.wait_for_text(r"(Alben|Ereignisse|Fotos)")
|
||||
machine.screenshot("lomiri-gallery_localised")
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user