Skip to content

Commit

Permalink
Fix data dir lookup for static tests
Browse files Browse the repository at this point in the history
pytest is not executed in the tuf_conformance source dir when the GitHub
Action is used. Build the data dir as relative from simulator_server.py
location.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
jku committed Aug 19, 2024
1 parent 07b2952 commit 56c2327
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions tuf_conformance/simulator_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ def debug_dump(self, test_name: str) -> None:
class StaticServer(ThreadingHTTPServer):
"""Web server to serve static repositories"""

data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static_data")

def __init__(self) -> None:
class _StaticReqHandler(BaseHTTPRequestHandler):
def do_GET(self) -> None: # noqa: N802
filepath = os.path.join("tuf_conformance", "static_data", self.path[1:])
filepath = os.path.join(StaticServer.data_dir, self.path[1:])
try:
with open(filepath, "rb") as f:
data = f.read()
Expand All @@ -108,7 +110,7 @@ def do_GET(self) -> None: # noqa: N802
self.timeout = 0

def new_test(self, static_dir: str) -> tuple[ClientInitData, str]:
sub_dir = os.path.join("tuf_conformance", "static_data", static_dir)
sub_dir = os.path.join(self.data_dir, static_dir)
with open(os.path.join(sub_dir, "initial_root.json"), "rb") as f:
initial_root = f.read()

Expand Down
4 changes: 2 additions & 2 deletions tuf_conformance/test_static_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from tuf_conformance.simulator_server import StaticServer

static_repos = []
for static_dir in os.listdir(os.path.join("tuf_conformance", "static_data")):
if os.path.isdir(os.path.join("tuf_conformance", "static_data", static_dir)):
for static_dir in os.listdir(StaticServer.data_dir):
if os.path.isdir(os.path.join(StaticServer.data_dir, static_dir)):
static_repos.append(static_dir)


Expand Down

0 comments on commit 56c2327

Please sign in to comment.