-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: Results verification #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kdvalin
wants to merge
12
commits into
main
Choose a base branch
from
feat/result-verify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
18b2175
feat(csv): Add basic csv to JSON conversion
kdvalin a32eeda
Feat: Add pydantic-based results verification script
kdvalin 860fc03
feat: Add flags for json and verification tools
kdvalin 2b58430
Feat: Add to_script_dir for convience
kdvalin 173ee16
fix(verify): Fix absolute path bugging out verfiy_results
kdvalin 6648581
refactor(csv_to_json): Change to using Pandas for CSV to JSON conversion
kdvalin ee9403b
Merge branch 'main' of github.com:redhat-performance/test_tools-wrapp…
kdvalin 055b3bd
fix(csv_to_json): Fix argument typos
kdvalin 85dce68
Fix(csv_to_json): Ignore comments/metadata
kdvalin 311928d
refactor(csv,validation): Install dependencies if needed
kdvalin d89c12f
Refactor(verify,csvjson): Simplify default arguments
kdvalin c0c2a7c
fix(verify_results): Change type of --schema_file
kdvalin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# License | ||
# | ||
# Copyright (C) 2025 Keith Valin [email protected] | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# Convert CSV files to JSON. | ||
|
||
import argparse | ||
import sys | ||
from typing import TextIO | ||
|
||
try: | ||
import pandas as pd | ||
except ImportError: | ||
print("WARNING: pandas is not installed. Installing using pip", file=sys.stderr) | ||
import subprocess | ||
subprocess.check_call([sys.executable, "-m", "pip", "install", "pandas", "--user", "--quiet"]) | ||
import pandas as pd | ||
|
||
def main(csv_file: TextIO, output: TextIO, separator: str): | ||
""" | ||
Convert a CSV file to JSON. | ||
""" | ||
df = pd.read_csv(csv_file, sep=separator, comment='#') | ||
df.to_json(output, orient='records', lines=False, indent=4) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Convert CSV files to JSON') | ||
parser.add_argument('--csv_file', type=argparse.FileType("r"), help='The CSV file to convert', default=sys.stdin) | ||
parser.add_argument('--output_file', type=argparse.FileType("w"), help='The JSON file to write', default=sys.stdout) | ||
parser.add_argument('--json_skip', action='store_true', help='Skip processing the CSV to JSON, effectively makes this a no-op') | ||
|
||
# Colon is used as the default separator since most wrappers use it. | ||
parser.add_argument('--separator', type=str, help='The separator to use for the CSV file', default=":") | ||
args = parser.parse_args() | ||
|
||
if args.json_skip: | ||
sys.exit(0) | ||
|
||
main(args.csv_file, args.output_file, args.separator) |
This file contains hidden or 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 hidden or 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,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import json | ||
from typing import TextIO | ||
|
||
try: | ||
from pydantic import BaseModel, TypeAdapter, ValidationError | ||
except ImportError as e: | ||
print("WARNING: Could not import pydantic, installing it using pip", file=sys.stderr) | ||
import subprocess | ||
subprocess.check_call([sys.executable, "-m", "pip", "install", "pydantic", "--user", "--quiet"]) | ||
from pydantic import BaseModel, TypeAdapter, ValidationError | ||
|
||
def verify_schema(file: TextIO, class_name: BaseModel): | ||
data = json.load(file) | ||
try: | ||
TypeAdapter(list[class_name]).validate_python(data) | ||
except ValidationError as e: | ||
print("Could not verify schema, see below for details", file=sys.stderr) | ||
print(e, file=sys.stderr) | ||
sys.exit(1) | ||
|
||
print("Results verified") | ||
|
||
if __name__ == "__main__": | ||
import argparse | ||
import importlib.util | ||
import re | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--file", | ||
type=argparse.FileType("r"), | ||
help="JSON file to verify, default is to read from stdin", | ||
default=sys.stdin | ||
) | ||
parser.add_argument("--schema_file", | ||
type=str, | ||
help="Schema file used to validate JSON file" | ||
) | ||
parser.add_argument("--class_name", type=str, help="Class name used to validate JSON file", default="Results") | ||
parser.add_argument("--usage", action="store_true", help="Show usage") | ||
parser.add_argument("--verify_skip", action="store_true", help="Skip verification process") | ||
args = parser.parse_args() | ||
|
||
if args.usage: | ||
parser.print_help() | ||
sys.exit(0) | ||
|
||
if args.verify_skip: | ||
sys.exit(0) | ||
|
||
try: | ||
# Get the file name (minus the extension), since it is the module name | ||
module_name = re.sub(r".py$", "", args.schema_file).split("/")[-1] | ||
|
||
# Import the class from the schema file | ||
spec = importlib.util.spec_from_file_location(module_name, args.schema_file) | ||
importedClass = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(importedClass) | ||
|
||
baseModel = getattr(importedClass, args.class_name) | ||
# Handle file issues and if the class is not found (attribute error) | ||
except (FileNotFoundError, AttributeError) as e: | ||
print(f"Class {args.class_name} not found in {args.schema_file}", file=sys.stderr) | ||
print(f"Error: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
except Exception as e: | ||
print(f"Error: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
verify_schema(args.file, baseModel) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the usage.