-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add infrastructure for test resources
We currently only have one test resource file, sample.coredump.zst, but the tests for #332 will add more. Create a package, tests.resources, to contain test resources and a function, get_resource(), to decompress them. It can also be used on the command line: python3 -m tests.resources $resource_name Signed-off-by: Omar Sandoval <osandov@osandov.com>
- Loading branch information
Showing
6 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!/.gitignore | ||
!/__init__.py | ||
!/__main__.py | ||
!*.zst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import os | ||
from pathlib import Path | ||
import subprocess | ||
import tempfile | ||
import unittest | ||
|
||
from util import out_of_date | ||
|
||
|
||
def get_resource(name: str) -> Path: | ||
dir = Path(__file__).parent | ||
decompressed_path = dir / name | ||
compressed_path = dir / (name + ".zst") | ||
if out_of_date(decompressed_path, compressed_path): | ||
tmp_file = tempfile.NamedTemporaryFile(dir=dir, prefix=name, delete=False) | ||
try: | ||
try: | ||
subprocess.check_call( | ||
[ | ||
"zstd", | ||
"--quiet", | ||
"--force", | ||
"--decompress", | ||
"--stdout", | ||
str(compressed_path), | ||
], | ||
stdout=tmp_file, | ||
) | ||
except FileNotFoundError: | ||
raise unittest.SkipTest("zstd not found") | ||
except BaseException: | ||
os.unlink(tmp_file.name) | ||
raise | ||
else: | ||
os.rename(tmp_file.name, decompressed_path) | ||
return decompressed_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import argparse | ||
|
||
from tests.resources import get_resource | ||
|
||
parser = argparse.ArgumentParser( | ||
description="decompress test resources and print their paths" | ||
) | ||
parser.add_argument("name", nargs="+", help="resource name") | ||
args = parser.parse_args() | ||
|
||
for name in args.name: | ||
print(get_resource(name)) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters