-
Notifications
You must be signed in to change notification settings - Fork 225
add CI test for auto plugin #5504
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
mafshari64
wants to merge
1
commit into
ComputationalRadiationPhysics:dev
Choose a base branch
from
mafshari64:ci_test_auto_plugin
base: dev
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
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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
""" | ||
This file is part of PIConGPU. | ||
Copyright 2025 PIConGPU contributors | ||
Authors: Julian Lenz | ||
Authors: Julian Lenz, Masoud Afshari | ||
License: GPLv3+ | ||
""" | ||
|
||
# flake8: noqa | ||
from .timestepspec import * # pyflakes.ignore | ||
from .auto import * # pyflakes.ignore |
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,64 @@ | ||
""" | ||
This file is part of PIConGPU. | ||
Copyright 2025 PIConGPU contributors | ||
Authors: Masoud Afshari | ||
License: GPLv3+ | ||
""" | ||
|
||
import unittest | ||
import typeguard | ||
from picongpu.picmi.diagnostics import Auto, TimeStepSpec | ||
from picongpu.pypicongpu.output.auto import Auto as PyPIConGPUAuto | ||
from picongpu.pypicongpu.output.timestepspec import TimeStepSpec as PyPIConGPUTimeStepSpec | ||
|
||
|
||
TESTCASES_VALID = [ | ||
(10, [{"start": 0, "stop": -1, "step": 10}]), | ||
(TimeStepSpec(slice(None, None, 10)), [{"start": 0, "stop": -1, "step": 10}]), | ||
] | ||
|
||
TESTCASES_INVALID = [ | ||
("invalid", "period must be an integer or TimeStepSpec"), | ||
(-10, "period must be non-negative"), | ||
] | ||
|
||
|
||
class PICMI_TestAuto(unittest.TestCase): | ||
def test_valid_periods(self): | ||
"""Test Auto instantiation, validation, and conversion.""" | ||
for period, expected_specs in TESTCASES_VALID: | ||
with self.subTest(period=period): | ||
auto = Auto(period=period) | ||
self.assertIsInstance(auto.period, TimeStepSpec) | ||
auto.check() | ||
|
||
# Convert to PyPIConGPUAuto | ||
pypicongpu_auto = auto.get_as_pypicongpu(0.5, 200) | ||
self.assertIsInstance(pypicongpu_auto, PyPIConGPUAuto) | ||
self.assertIsInstance(pypicongpu_auto.period, PyPIConGPUTimeStepSpec) | ||
|
||
# Validate rendered specs | ||
serialized = pypicongpu_auto.get_rendering_context() | ||
self.assertTrue(serialized["typeID"]["auto"]) | ||
self.assertEqual(serialized["data"]["period"]["specs"], expected_specs) | ||
|
||
def test_invalid_period_type(self): | ||
"""Test invalid input types.""" | ||
with self.assertRaises(typeguard.TypeCheckError): | ||
Auto(period="invalid") | ||
|
||
def test_negative_period(self): | ||
"""Test negative integer period raises error.""" | ||
with self.assertRaisesRegex(ValueError, "period must be non-negative"): | ||
Auto(period=-5) | ||
|
||
def test_check_invalid_period(self): | ||
"""Test that check() catches wrong type.""" | ||
auto = Auto(period=10) | ||
auto.period = "invalid" | ||
with self.assertRaisesRegex(TypeError, "period must be a TimeStepSpec"): | ||
auto.check() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.
What's the difference between this line and line 57+58?
And why are both tests needed?
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.
The key difference is when and how the invalid value is introduced.
test_invalid_period_type is done During def init. Auto is decorated with @typeguard.typechecked, typeguard automatically checks the type of auto period. so the error happens during object creation.
test_check_invalid_period is During check(). first we create a valid object: Auto(period=10). then, we manually break it by assigning an invalid value to auto.period.. Typeguard does not automatically recheck assignments. auto.check(), then raises a TypeError because period is no longer a TimeStepSpec.