summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/invisible-watermark/tests/python/default.nix
blob: 617dd0bb13cb0ab8e074ba4a10af6660d8998812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  image,
  invisible-watermark,
  opencv4,
  python,
  runCommand,
  stdenvNoCC,
}:

# This test checks if the python code shown in the README works correctly

let
  message = "fnörd1";
  method = "dwtDct";

  pythonWithPackages = python.withPackages (_: [
    invisible-watermark
    opencv4
  ]);
  pythonInterpreter = pythonWithPackages.interpreter;

  encode = stdenvNoCC.mkDerivation {
    name = "encode";
    realBuilder = pythonInterpreter;
    args = [ ./encode.py ];
    inherit image message method;
  };

  decode = stdenvNoCC.mkDerivation {
    name = "decode";
    realBuilder = pythonInterpreter;
    args = [ ./decode.py ];
    inherit method;
    image = "${encode}/test_wm.png";
    num_bits = (builtins.stringLength message) * 8;
  };
in
runCommand "invisible-watermark-test-python" { } ''
  decoded_message="$(cat '${decode}')"
  if [ '${message}' != "$decoded_message" ]; then
    echo "invisible-watermark did not decode the watermark correctly."
    echo "The original message was ${message} but the decoded message was $decoded_message."
    exit 1
  fi
  touch "$out"
''