-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for `FrozenClass` where attributes could be added multiple times. * Didn't find a nice quick fix for attributes being added to all classes * Fixed test
- Loading branch information
1 parent
97e238e
commit 63c2b79
Showing
2 changed files
with
48 additions
and
3 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,36 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.base | ||
def test_frozen_class(): | ||
from pySDC.helpers.pysdc_helper import FrozenClass | ||
|
||
class Dummy(FrozenClass): | ||
pass | ||
|
||
me = Dummy() | ||
me.add_attr('foo') | ||
|
||
me.foo = 0 | ||
|
||
you = Dummy() | ||
you.foo = 1 | ||
assert me.foo != you.foo, 'Attribute is shared between class instances' | ||
|
||
me = Dummy() | ||
assert me.foo is None, 'Attribute persists after reinstantiation' | ||
|
||
me.add_attr('foo') | ||
assert Dummy.attrs.count('foo') == 1, 'Attribute was added too many times' | ||
|
||
class Dummy2(FrozenClass): | ||
pass | ||
|
||
Dummy2.add_attr('bar') | ||
you = Dummy2() | ||
you.bar = 5 | ||
assert me.bar is None, 'Attribute was set across classes' | ||
|
||
|
||
if __name__ == '__main__': | ||
test_frozen_class() |