1+ from meshroom .core .graph import Graph
2+ import math
3+ import logging
4+
5+ logger = logging .getLogger ('test' )
6+
7+
8+ def test_groupAttributes_with_same_structure_can_be_linked_and_only_calue_is_copied ():
9+
10+ # Given
11+ graph = Graph ()
12+ position = graph .addNewNode ("Position" )
13+ color = graph .addNewNode ("Color" )
14+
15+ # When
16+ graph .addEdge (position .xyz , color .rgb )
17+ position .xyz .x .value = 1.0
18+ position .xyz .y .value = 2.0
19+ position .xyz .z .value = 3.0
20+
21+ # Then
22+ assert color .rgb .value != position .xyz .value
23+ assert math .isclose (color .rgb .r .value , position .xyz .x .value )
24+ assert math .isclose (color .rgb .g .value , position .xyz .y .value )
25+ assert math .isclose (color .rgb .b .value , position .xyz .z .value )
26+ assert math .isclose (color .rgb .r .value , 1.0 )
27+ assert math .isclose (color .rgb .g .value , 2.0 )
28+ assert math .isclose (color .rgb .b .value , 3.0 )
29+
30+ def test_groupAttributes_with_same_nested_structure_can_be_linked_and_only_calue_is_copied ():
31+
32+ # Given
33+ graph = Graph ()
34+ nestedColor = graph .addNewNode ("NestedColor" )
35+ nestedPosition = graph .addNewNode ("NestedPosition" )
36+
37+ # When
38+ graph .addEdge (nestedPosition .xyz , nestedColor .rgb )
39+ nestedPosition .xyz .x .value = 1.0
40+ nestedPosition .xyz .y .value = 2.0
41+ nestedPosition .xyz .z .value = 3.0
42+ nestedPosition .xyz .test .x .value = 4.0
43+ nestedPosition .xyz .test .y .value = 5.0
44+ nestedPosition .xyz .test .z .value = 6.0
45+
46+ # Then
47+ assert nestedColor .rgb .value != nestedPosition .xyz .test .value
48+ assert math .isclose (nestedColor .rgb .r .value , nestedPosition .xyz .x .value )
49+ assert math .isclose (nestedColor .rgb .g .value , nestedPosition .xyz .y .value )
50+ assert math .isclose (nestedColor .rgb .b .value , nestedPosition .xyz .z .value )
51+ assert math .isclose (nestedColor .rgb .test .r .value , nestedPosition .xyz .test .x .value )
52+ assert math .isclose (nestedColor .rgb .test .g .value , nestedPosition .xyz .test .y .value )
53+ assert math .isclose (nestedColor .rgb .test .b .value , nestedPosition .xyz .test .z .value )
54+ assert math .isclose (nestedColor .rgb .r .value , 1.0 )
55+ assert math .isclose (nestedColor .rgb .g .value , 2.0 )
56+ assert math .isclose (nestedColor .rgb .b .value , 3.0 )
57+ assert math .isclose (nestedColor .rgb .test .r .value , 4.0 )
58+ assert math .isclose (nestedColor .rgb .test .g .value , 5.0 )
59+ assert math .isclose (nestedColor .rgb .test .b .value , 6.0 )
60+
61+ def test_groupAttributes_with_smae_structure_should_allow_connection ():
62+
63+ # Given
64+ graph = Graph ()
65+ nestedPosition = graph .addNewNode ("NestedPosition" )
66+ nestedColor = graph .addNewNode ("NestedColor" )
67+
68+ # When
69+ acceptedConnection = nestedPosition .xyz .validateConnectionFrom (nestedColor .rgb )
70+
71+ # Then
72+ assert acceptedConnection == True
73+
74+ def test_groupAttributes_with_different_structure_should_not_allow_connection ():
75+
76+ # Given
77+ graph = Graph ()
78+ nestedPosition = graph .addNewNode ("NestedPosition" )
79+ nestedTest = graph .addNewNode ("NestedTest" )
80+
81+ # When
82+ acceptedConnection = nestedPosition .xyz .validateConnectionFrom (nestedTest .xyz )
83+
84+ # Then
85+ assert acceptedConnection == False
0 commit comments