Skip to content
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

pytests: Add conftest.py and other tests #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

prashant1221
Copy link
Contributor

@prashant1221 prashant1221 commented Aug 26, 2024

conftest.py contain common fixtures to setup and teardown.
We use them wherever feasible

Added Configurations and Hardware section tests in tests_all_configs.
It tests the keys present under those section in our config file.

pytest/test_raw_image_option.py checks .img if provided instead
of vmdk should still work.
After that it matches values for the same in ovf and our yaml.

Copy link
Contributor

@oliverkurth oliverkurth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, please add comments to your code, explaining what is tested.

Comment on lines 62 to 78
in_yaml = os.path.join(CONFIG_DIR, "raw-image.yaml")

basename = os.path.basename(in_yaml.rsplit(".", 1)[0])
out_ovf = os.path.join(WORK_DIR, f"{basename}.ovf")

process = subprocess.run([OVA_COMPOSE, "-i", in_yaml, "-o", out_ovf, "--vmdk-convert", VMDK_CONVERT], cwd=WORK_DIR)
assert process.returncode == 0

with open(in_yaml) as f:
yaml_loader = yaml.SafeLoader
yaml_loader.app_params = {}
yaml.add_constructor("!param", yaml_param, Loader=yaml_loader)
config = yaml.load(f, Loader=yaml_loader)

with open(out_ovf) as f:
ovf = xmltodict.parse(f.read())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is also in test_all_configs.py, so I think this should be in a common file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

with open(out_ovf) as f:
ovf = xmltodict.parse(f.read())

test_all_configs.test_envelope_configs((config, ovf))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like invoking a function in another test_*.py file - so I think test_envelope_configs shopuld be in a separate file, that is imported by both test_all_configs.py and test_raw_image_option.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

pytest/test_raw_image_option.py Outdated Show resolved Hide resolved
conftest.py contain common fixtures to setup and teardown.
We use them wherever feasible

Added Configurations and Hardware section tests in tests_all_configs.
It tests the keys present under those section in our config file.

pytest/test_raw_image_option.py checks .img if provided instead
of vmdk should still work.
After that it matches values for the same in ovf and our yaml.
@prashant1221 prashant1221 reopened this Sep 17, 2024
@prashant1221 prashant1221 marked this pull request as ready for review September 17, 2024 08:31
@prashant1221 prashant1221 changed the title pytests: Add test for raw_image option pytests: Add conftest.py and other tests Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants