Skip to content

Commit

Permalink
Add output to BaseTest, add Graph Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reglim committed Dec 13, 2023
1 parent 486e864 commit 2ee09ab
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class BaseTest(object):
gpgFinder = GPGFinder()
dotFinder = DotFinder()

output: bytes | None = None

def test(self):
self.prepare()
try:
Expand Down
68 changes: 68 additions & 0 deletions system/t13_graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from PIL import Image
import time
import re
import os
from lib import BaseTest


Expand All @@ -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)

0 comments on commit 2ee09ab

Please sign in to comment.