From 2ee09ab3b7830bb00f3c5c219ad77ce91c37d30a Mon Sep 17 00:00:00 2001 From: Mauro Regli Date: Wed, 13 Dec 2023 09:45:04 +0100 Subject: [PATCH] Add output to BaseTest, add Graph Tests --- system/lib.py | 2 ++ system/t13_graph/graph.py | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/system/lib.py b/system/lib.py index 951daa6bd..096ef7fac 100644 --- a/system/lib.py +++ b/system/lib.py @@ -171,6 +171,8 @@ class BaseTest(object): gpgFinder = GPGFinder() dotFinder = DotFinder() + output: bytes | None = None + def test(self): self.prepare() try: diff --git a/system/t13_graph/graph.py b/system/t13_graph/graph.py index 1d4bd7050..0b5026957 100644 --- a/system/t13_graph/graph.py +++ b/system/t13_graph/graph.py @@ -1,4 +1,7 @@ from PIL import Image +import time +import re +import os from lib import BaseTest @@ -23,3 +26,68 @@ def check(self): # check is horizontal self.check_gt(width, height) img.verify() + + os.remove("graph.png") + + +class GraphTest2(BaseTest): + """ + Test that the graph is correctly generate when vertical layout is specified. + """ + + fixtureDB = True + fixturePool = True + fixtureCmds = [ + "aptly snapshot create snap2 from mirror gnuplot-maverick", + "aptly publish snapshot -skip-signing snap2", + ] + runCmd = "aptly graph -output=graph.png -layout=vertical" + + def check(self): + self.check_exists_in_cwd("graph.png") + + with Image.open("graph.png") as img: + (width, height) = img.size + # check is horizontal + self.check_gt(height, width) + img.verify() + + os.remove("graph.png") + + +class GraphTest3(BaseTest): + """ + Test that the graph is accessible at the temporary + file path aptly prints. + """ + + fixtureDB = True + fixturePool = True + fixtureCmds = [ + "aptly snapshot create snap3 from mirror gnuplot-maverick", + "aptly publish snapshot -skip-signing snap3", + ] + runCmd = "aptly graph" + + def check(self): + assert self.output is not None + + file_regex = re.compile(r": (\S+).png") + temp_file = file_regex.search(self.output.decode()) + + assert temp_file is not None + temp_file = temp_file.group(1) + ".png" + + self.check_exists(temp_file) + with Image.open(temp_file) as img: + (width, height) = img.size + # check is horizontal + self.check_gt(width, height) + img.verify() + + # wait 1s to make sure it still exists + time.sleep(1) + + assert os.path.isfile(temp_file) + + os.remove(temp_file)