This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Add megic_pointer to generate convenient references
- Loading branch information
Showing
4 changed files
with
212 additions
and
27 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
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,56 @@ | ||
import pytest | ||
|
||
from faebryk.core.node import InitVar, Node, magic_pointer | ||
|
||
|
||
def test_points_to_correct_node(): | ||
class A(Node): | ||
pass | ||
|
||
class B(Node): | ||
x: InitVar[A] = magic_pointer(A) | ||
|
||
a = A() | ||
b = B() | ||
b.x = a | ||
assert b.x is a | ||
|
||
|
||
def test_immutable(): | ||
class A(Node): | ||
pass | ||
|
||
class B(Node): | ||
x: InitVar[A] = magic_pointer(A) | ||
|
||
b = B() | ||
a = A() | ||
b.x = a | ||
assert b.x is a | ||
|
||
with pytest.raises(TypeError): | ||
b.x = A() | ||
|
||
|
||
def test_unset(): | ||
class A(Node): | ||
pass | ||
|
||
class B(Node): | ||
x: InitVar[A] = magic_pointer(A) | ||
|
||
b = B() | ||
with pytest.raises(AttributeError): | ||
b.x | ||
|
||
|
||
def test_wrong_type(): | ||
class A(Node): | ||
pass | ||
|
||
class B(Node): | ||
x: InitVar[A] = magic_pointer(A) | ||
|
||
b = B() | ||
with pytest.raises(TypeError): | ||
b.x = 1 |