1- import pytest
2- import compas
31import json
4- from random import random , randint
2+ import os
3+ import random
4+
5+ import pytest
56
7+ import compas
68from compas .datastructures import Network
79from compas .geometry import Pointcloud
810
9-
1011# ==============================================================================
1112# Fixtures
1213# ==============================================================================
1314
15+ BASE_FOLDER = os .path .dirname (__file__ )
16+
17+
18+ @pytest .fixture
19+ def planar_network ():
20+ return Network .from_obj (os .path .join (BASE_FOLDER , "fixtures" , "planar.obj" ))
21+
22+
23+ @pytest .fixture
24+ def non_planar_network ():
25+ return Network .from_obj (os .path .join (BASE_FOLDER , "fixtures" , "non-planar.obj" ))
26+
1427
1528@pytest .fixture
1629def k5_network ():
@@ -57,7 +70,7 @@ def test_network_from_obj(filepath):
5770
5871
5972def test_network_from_pointcloud ():
60- cloud = Pointcloud .from_bounds (random (), random (), random (), randint (10 , 100 ))
73+ cloud = Pointcloud .from_bounds (random . random (), random . random (), random . random (), random . randint (10 , 100 ))
6174 network = Network .from_pointcloud (cloud = cloud , degree = 3 )
6275 assert network .number_of_nodes () == len (cloud )
6376 for node in network .nodes ():
@@ -70,7 +83,7 @@ def test_network_from_pointcloud():
7083
7184
7285def test_network_data ():
73- cloud = Pointcloud .from_bounds (random (), random (), random (), randint (10 , 100 ))
86+ cloud = Pointcloud .from_bounds (random . random (), random . random (), random . random (), random . randint (10 , 100 ))
7487 network = Network .from_pointcloud (cloud = cloud , degree = 3 )
7588 other = Network .from_data (json .loads (json .dumps (network .data )))
7689
@@ -123,24 +136,20 @@ def test_add_node():
123136# ==============================================================================
124137
125138
126- def test_non_planar (k5_network ):
127- try :
128- import planarity # noqa: F401
129- except ImportError :
139+ def test_non_planar (k5_network , non_planar_network ):
140+ # On IronPython, we completely skip adding the is_planar method because it depends on c-extensions (networkx)
141+ if not hasattr (k5_network , "is_planar" ):
130142 return
131143
132- from compas .datastructures import network_is_planar
133-
134- assert network_is_planar (k5_network ) is not True
144+ assert k5_network .is_planar () is not True
145+ assert non_planar_network .is_planar () is not True
135146
136147
137- def test_planar (k5_network ):
138- try :
139- import planarity # noqa: F401
140- except ImportError :
148+ def test_planar (k5_network , planar_network ):
149+ # On IronPython, we completely skip adding the is_planar method because it depends on c-extensions (networkx)
150+ if not hasattr (k5_network , "is_planar" ):
141151 return
142152
143- from compas .datastructures import network_is_planar
144-
145153 k5_network .delete_edge (("a" , "b" )) # Delete (a, b) edge to make K5 planar
146- assert network_is_planar (k5_network ) is True
154+ assert k5_network .is_planar () is True
155+ assert planar_network .is_planar () is True
0 commit comments