Skip to content

Commit f4f8903

Browse files
committed
nixos/tests/cups-pdf: migration to runTest
#386873
1 parent 2c8d3f4 commit f4f8903

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ in
343343
crabfit = handleTest ./crabfit.nix { };
344344
cri-o = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cri-o.nix { };
345345
cryptpad = runTest ./cryptpad.nix;
346-
cups-pdf = handleTest ./cups-pdf.nix { };
346+
cups-pdf = runTest ./cups-pdf.nix;
347347
curl-impersonate = handleTest ./curl-impersonate.nix { };
348348
custom-ca = handleTest ./custom-ca.nix { };
349349
croc = handleTest ./croc.nix { };

nixos/tests/cups-pdf.nix

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1-
import ./make-test-python.nix (
2-
{ lib, pkgs, ... }:
3-
{
4-
name = "cups-pdf";
1+
{ hostPkgs, lib, ... }:
2+
{
3+
name = "cups-pdf";
54

6-
nodes.machine =
7-
{ pkgs, ... }:
8-
{
9-
imports = [ ./common/user-account.nix ];
10-
environment.systemPackages = [ pkgs.poppler-utils ];
11-
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
12-
services.printing.cups-pdf.enable = true;
13-
services.printing.cups-pdf.instances = {
14-
opt = { };
15-
noopt.installPrinter = false;
16-
};
17-
hardware.printers.ensurePrinters = [
18-
{
19-
name = "noopt";
20-
model = "CUPS-PDF_noopt.ppd";
21-
deviceUri = "cups-pdf:/noopt";
22-
}
23-
];
5+
nodes.machine =
6+
{ pkgs, ... }:
7+
{
8+
imports = [ ./common/user-account.nix ];
9+
environment.systemPackages = [ pkgs.poppler-utils ];
10+
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
11+
services.printing.cups-pdf.enable = true;
12+
services.printing.cups-pdf.instances = {
13+
opt = { };
14+
noopt.installPrinter = false;
2415
};
16+
hardware.printers.ensurePrinters = [
17+
{
18+
name = "noopt";
19+
model = "CUPS-PDF_noopt.ppd";
20+
deviceUri = "cups-pdf:/noopt";
21+
}
22+
];
23+
};
2524

26-
# we cannot check the files with pdftotext, due to
27-
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
28-
# we need `imagemagickBig` as it has ghostscript support
25+
# we cannot check the files with pdftotext, due to
26+
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
27+
# we need `imagemagickBig` as it has ghostscript support
2928

30-
testScript = ''
31-
from subprocess import run
32-
machine.wait_for_unit("multi-user.target")
33-
for name in ("opt", "noopt"):
34-
text = f"test text {name}".upper()
35-
machine.wait_until_succeeds(f"lpstat -v {name}")
36-
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
37-
# wait until the pdf files are completely produced and readable by alice
38-
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
39-
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
40-
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
41-
run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
42-
assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
43-
'';
29+
testScript = ''
30+
from subprocess import run
31+
machine.wait_for_unit("multi-user.target")
32+
for name in ("opt", "noopt"):
33+
text = f"test text {name}".upper()
34+
machine.wait_until_succeeds(f"lpstat -v {name}")
35+
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
36+
# wait until the pdf files are completely produced and readable by alice
37+
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
38+
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
39+
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
40+
run(f"${hostPkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
41+
assert text.encode() in run(f"${lib.getExe hostPkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
42+
'';
4443

45-
meta.maintainers = [ lib.maintainers.yarny ];
46-
}
47-
)
44+
meta.maintainers = [ lib.maintainers.yarny ];
45+
}

0 commit comments

Comments
 (0)