-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from canonical/fix-dcbase-dedup
dedup dcbase.replace
- Loading branch information
Showing
4 changed files
with
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" | |
[project] | ||
name = "ops-scenario" | ||
|
||
version = "4.0.1" | ||
version = "4.0.2" | ||
|
||
authors = [ | ||
{ name = "Pietro Pasotti", email = "[email protected]" } | ||
|
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
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,41 @@ | ||
import dataclasses | ||
from typing import Dict, List | ||
|
||
from scenario.state import _DCBase | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Foo(_DCBase): | ||
a: int | ||
b: List[int] | ||
c: Dict[int, List[int]] | ||
|
||
|
||
def test_base_case(): | ||
l = [1, 2] | ||
l1 = [1, 2, 3] | ||
d = {1: l1} | ||
f = Foo(1, l, d) | ||
g = f.replace(a=2) | ||
|
||
assert g.a == 2 | ||
assert g.b == l | ||
assert g.c == d | ||
assert g.c[1] == l1 | ||
|
||
|
||
def test_dedup_on_replace(): | ||
l = [1, 2] | ||
l1 = [1, 2, 3] | ||
d = {1: l1} | ||
f = Foo(1, l, d) | ||
g = f.replace(a=2) | ||
|
||
l.append(3) | ||
l1.append(4) | ||
d[2] = "foobar" | ||
|
||
assert g.a == 2 | ||
assert g.b == [1, 2] | ||
assert g.c == {1: [1, 2, 3]} | ||
assert g.c[1] == [1, 2, 3] |