Skip to content

Commit a18930f

Browse files
authored
Unit tests Refactoring (#905)
* Refactoring UnitTest setup and TearDown * Fix on Flake 8 * Fix on Flake 8 * Fix on Flake 8 * Fix on Flake 8 * Fix on Flake 8 * Fix on Flake 8 * Fix on Teardown * Fix on Teardown * added confest to omit list of code coverage * Fixed example edb issues Co-authored-by: maxcapodi78 <Shark78>
1 parent 1f79ea5 commit a18930f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+276
-328
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[run]
2-
omit = examples/**/*, doc/**/*, testvenv/Lib/**/*, third_party/**/*, pyaedt/generic/toolkit.py, pyaedt/common_rpc.py, pyaedt/conftest.py, pyaedt/rpc/*, pyaed/misc/aedtlib_personalib_install.py, pyaedt/doctest_fixtures/*
2+
omit = examples/**/*, doc/**/*, testvenv/Lib/**/*, third_party/**/*, pyaedt/generic/toolkit.py, pyaedt/common_rpc.py, pyaedt/conftest.py, pyaedt/rpc/*, pyaed/misc/aedtlib_personalib_install.py, pyaedt/doctest_fixtures/*, pyaedt/_unittest/conftest.py

_unittest/conftest.py

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
import json
2424
import gc
2525
import sys
26-
from pyaedt.generic.general_methods import is_ironpython, inside_desktop
26+
from pyaedt.generic.general_methods import is_ironpython, inside_desktop, generate_unique_name
2727
from pyaedt import settings
2828

2929
log_path = os.path.join(tempfile.gettempdir(), "test.log")
3030
if os.path.exists(os.path.join(tempfile.gettempdir(), "test.log")):
3131
os.remove(log_path)
3232
settings.logger_file_path = log_path
3333
settings.enable_error_handler = False
34+
settings.enable_desktop_logs = False
3435
if is_ironpython:
3536
import _unittest_ironpython.conf_unittest as pytest
3637
else:
@@ -42,7 +43,7 @@
4243
from pyaedt import Desktop
4344

4445
# Import required modules
45-
from pyaedt import Hfss
46+
from pyaedt import Hfss, Edb
4647
from pyaedt.generic.filesystem import Scratch
4748

4849
test_project_name = "test_primitives"
@@ -79,37 +80,76 @@
7980

8081

8182
class BasisTest(object):
82-
def my_setup(self, project_name=None, design_name=None, solution_type=None, application=None):
83-
84-
with Scratch(scratch_path) as self.local_scratch:
85-
if project_name:
86-
example_project = os.path.join(local_path, "example_models", project_name + ".aedt")
87-
if os.path.exists(example_project):
88-
self.test_project = self.local_scratch.copyfile(example_project)
89-
else:
90-
self.test_project = None
91-
else:
92-
self.test_project = None
93-
if not application:
94-
application = Hfss
83+
def my_setup(self):
84+
self.local_scratch = Scratch(scratch_path)
85+
self.aedtapps = []
86+
self.edbapps = []
9587

96-
self.aedtapp = application(
88+
def my_teardown(self):
89+
try:
90+
oDesktop = sys.modules["__main__"].oDesktop
91+
except Exception as e:
92+
oDesktop = None
93+
if oDesktop:
94+
oDesktop.ClearMessages("", "", 3)
95+
for edbapp in self.edbapps[::-1]:
96+
try:
97+
edbapp.close_edb()
98+
except:
99+
pass
100+
del self.edbapps
101+
for aedtapp in self.aedtapps[::-1]:
102+
try:
103+
aedtapp.close_project(None, False)
104+
except:
105+
pass
106+
del self.aedtapps
107+
108+
def add_app(self, project_name=None, design_name=None, solution_type=None, application=None):
109+
if project_name:
110+
example_project = os.path.join(local_path, "example_models", project_name + ".aedt")
111+
example_folder = os.path.join(local_path, "example_models", project_name + ".aedb")
112+
if os.path.exists(example_project):
113+
self.test_project = self.local_scratch.copyfile(example_project)
114+
elif os.path.exists(example_project + "z"):
115+
example_project = example_project + "z"
116+
self.test_project = self.local_scratch.copyfile(example_project)
117+
else:
118+
self.test_project = project_name
119+
if os.path.exists(example_folder):
120+
target_folder = os.path.join(self.local_scratch.path, project_name + ".aedb")
121+
self.local_scratch.copyfolder(example_folder, target_folder)
122+
else:
123+
self.test_project = None
124+
if not application:
125+
application = Hfss
126+
self.aedtapps.append(
127+
application(
97128
projectname=self.test_project,
98129
designname=design_name,
99130
solution_type=solution_type,
100131
specified_version=desktop_version,
101132
)
102-
self.project_name = self.aedtapp.project_name
103-
104-
def my_teardown(self):
105-
self.aedtapp._desktop.ClearMessages("", "", 3)
106-
list_of_projects = list(self.aedtapp._desktop.GetProjectList())
107-
for project in list_of_projects:
108-
try:
109-
self.aedtapp._desktop.CloseProject(project)
110-
except: # pragma: no cover
111-
pass
112-
del self.aedtapp
133+
)
134+
return self.aedtapps[-1]
135+
136+
def add_edb(self, project_name=None):
137+
if project_name:
138+
example_folder = os.path.join(local_path, "example_models", project_name + ".aedb")
139+
if os.path.exists(example_folder):
140+
target_folder = os.path.join(self.local_scratch.path, project_name + ".aedb")
141+
self.local_scratch.copyfolder(example_folder, target_folder)
142+
else:
143+
target_folder = os.path.join(self.local_scratch.path, project_name + ".aedb")
144+
else:
145+
target_folder = os.path.join(self.local_scratch.path, generate_unique_name("TestEdb") + ".aedb")
146+
self.edbapps.append(
147+
Edb(
148+
target_folder,
149+
edbversion=desktop_version,
150+
)
151+
)
152+
return self.edbapps[-1]
113153

114154
def teardown(self):
115155
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": true, "2": false, "3": false, "4": false}, "Layer": {"Simple": true, "Double": false, "Triple": false}, "Layer Type": {"Separate": true, "Linked": false}, "Similar Layer": {"Similar": true, "Different": false}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Hexagon": false, "Octagon": false, "Circle": true}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 19.45, "Outer Radius": 50.55, "Height": 21.1, "Wire Diameter": 1, "Turns": 111, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.96166666666666}, "Mid Winding": {"Turns": 111, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.96166666666666}, "Inner Winding": {"Turns": 111, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.96166666666666}}
1+
{"Mid Winding": {"Turns": 111, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.961666666666659}, "Layer": {"Double": false, "Simple": true, "Triple": false}, "Number of Windings": {"4": false, "1": true, "3": false, "2": false}, "Similar Layer": {"Different": false, "Similar": true}, "Inner Winding": {"Turns": 111, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.961666666666659}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Circle": true, "Octagon": false, "Hexagon": false}, "Outer Winding": {"Turns": 111, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 50.55, "Inner Radius": 19.45, "Coil Pit(deg)": 1.621, "Occupation(%)": 99.961666666666659, "Height": 21.1}, "Layer Type": {"Separate": true, "Linked": false}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": true, "2": false, "3": false, "4": false}, "Layer": {"Simple": false, "Double": false, "Triple": true}, "Layer Type": {"Separate": false, "Linked": true}, "Similar Layer": {"Similar": false, "Different": true}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Hexagon": false, "Octagon": false, "Circle": true}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 17.25, "Outer Radius": 52.75, "Height": 25.5, "Wire Diameter": 1, "Turns": 98, "Coil Pit(deg)": 1.836, "Occupation(%)": 99.96}, "Mid Winding": {"Turns": 104, "Coil Pit(deg)": 1.731, "Occupation(%)": 100.01333333333334}, "Inner Winding": {"Turns": 111, "Coil Pit(deg)": 1.622, "Occupation(%)": 100.02333333333334}}
1+
{"Mid Winding": {"Turns": 104, "Coil Pit(deg)": 1.731, "Occupation(%)": 100.01333333333334}, "Layer": {"Double": false, "Simple": false, "Triple": true}, "Number of Windings": {"4": false, "1": true, "3": false, "2": false}, "Similar Layer": {"Different": true, "Similar": false}, "Inner Winding": {"Turns": 111, "Coil Pit(deg)": 1.622, "Occupation(%)": 100.02333333333334}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Circle": true, "Octagon": false, "Hexagon": false}, "Outer Winding": {"Turns": 98, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 52.75, "Inner Radius": 17.25, "Coil Pit(deg)": 1.836, "Occupation(%)": 99.96, "Height": 25.5}, "Layer Type": {"Separate": false, "Linked": true}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": false, "2": true, "3": false, "4": false}, "Layer": {"Simple": true, "Double": false, "Triple": false}, "Layer Type": {"Separate": true, "Linked": false}, "Similar Layer": {"Similar": true, "Different": false}, "Mode": {"Differential": false, "Common": true}, "Wire Section": {"None": false, "Hexagon": false, "Octagon": true, "Circle": false}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 19.45, "Outer Radius": 50.55, "Height": 21.1, "Wire Diameter": 1, "Turns": 10, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113}, "Mid Winding": {"Turns": 10, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113}, "Inner Winding": {"Turns": 10, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113}}
1+
{"Mid Winding": {"Turns": 10, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113}, "Layer": {"Double": false, "Simple": true, "Triple": false}, "Number of Windings": {"4": false, "1": false, "3": false, "2": true}, "Similar Layer": {"Different": false, "Similar": true}, "Inner Winding": {"Turns": 10, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113}, "Mode": {"Differential": false, "Common": true}, "Wire Section": {"None": false, "Circle": false, "Octagon": true, "Hexagon": false}, "Outer Winding": {"Turns": 10, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 50.55, "Inner Radius": 19.45, "Coil Pit(deg)": 1.621, "Occupation(%)": 18.011111111111113, "Height": 21.1}, "Layer Type": {"Separate": true, "Linked": false}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": false, "2": true, "3": false, "4": false}, "Layer": {"Simple": false, "Double": true, "Triple": false}, "Layer Type": {"Separate": true, "Linked": false}, "Similar Layer": {"Similar": true, "Different": false}, "Mode": {"Differential": false, "Common": true}, "Wire Section": {"None": false, "Hexagon": true, "Octagon": false, "Circle": false}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 18.35, "Outer Radius": 51.65, "Height": 23.3, "Wire Diameter": 1, "Turns": 25, "Coil Pit(deg)": 1.718, "Occupation(%)": 47.72222222222222}, "Mid Winding": {"Turns": 25, "Coil Pit(deg)": 1.718, "Occupation(%)": 47.72222222222222}, "Inner Winding": {"Turns": 25, "Coil Pit(deg)": 1.718, "Occupation(%)": 47.72222222222222}}
1+
{"Mid Winding": {"Turns": 25, "Coil Pit(deg)": 1.7998, "Occupation(%)": 99.9888888888889}, "Layer": {"Double": true, "Simple": false, "Triple": false}, "Number of Windings": {"4": true, "1": false, "3": false, "2": false}, "Similar Layer": {"Different": true, "Similar": false}, "Inner Winding": {"Turns": 20, "Coil Pit(deg)": 3.8227, "Occupation(%)": 84.948888888888888}, "Mode": {"Differential": false, "Common": true}, "Wire Section": {"None": false, "Circle": true, "Octagon": false, "Hexagon": false}, "Outer Winding": {"Turns": 25, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 51.65, "Inner Radius": 18.35, "Coil Pit(deg)": 1.718, "Occupation(%)": 95.444444444444443, "Height": 23.3}, "Layer Type": {"Separate": true, "Linked": false}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": false, "2": true, "3": false, "4": false}, "Layer": {"Simple": false, "Double": true, "Triple": false}, "Layer Type": {"Separate": false, "Linked": true}, "Similar Layer": {"Similar": false, "Different": true}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Hexagon": true, "Octagon": false, "Circle": false}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 18.35, "Outer Radius": 51.65, "Height": 23.3, "Wire Diameter": 1, "Turns": 12, "Coil Pit(deg)": 1.718, "Occupation(%)": 22.906666666666666}, "Mid Winding": {"Turns": 14, "Coil Pit(deg)": 1.621, "Occupation(%)": 25.215555555555557}, "Inner Winding": {"Turns": 20, "Coil Pit(deg)": 0.1, "Occupation(%)": 84.94888888888889}}
1+
{"Mid Winding": {"Turns": 14, "Coil Pit(deg)": 1.621, "Occupation(%)": 25.215555555555557}, "Layer": {"Double": true, "Simple": false, "Triple": false}, "Number of Windings": {"4": false, "1": false, "3": false, "2": true}, "Similar Layer": {"Different": true, "Similar": false}, "Inner Winding": {"Turns": 20, "Coil Pit(deg)": 0.10000000000000001, "Occupation(%)": 84.948888888888888}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Circle": false, "Octagon": false, "Hexagon": true}, "Outer Winding": {"Turns": 12, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 51.65, "Inner Radius": 18.35, "Coil Pit(deg)": 1.718, "Occupation(%)": 22.906666666666666, "Height": 23.3}, "Layer Type": {"Separate": false, "Linked": true}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": false, "2": false, "3": true, "4": false}, "Layer": {"Simple": false, "Double": false, "Triple": true}, "Layer Type": {"Separate": true, "Linked": false}, "Similar Layer": {"Similar": true, "Different": false}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": true, "Hexagon": false, "Octagon": false, "Circle": false}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 17.25, "Outer Radius": 52.75, "Height": 25.5, "Wire Diameter": 1, "Turns": 15, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7}, "Mid Winding": {"Turns": 15, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7}, "Inner Winding": {"Turns": 15, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7}}
1+
{"Mid Winding": {"Turns": 15, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7}, "Layer": {"Double": false, "Simple": false, "Triple": true}, "Number of Windings": {"4": false, "1": false, "3": true, "2": false}, "Similar Layer": {"Different": false, "Similar": true}, "Inner Winding": {"Turns": 15, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": true, "Circle": false, "Octagon": false, "Hexagon": false}, "Outer Winding": {"Turns": 15, "Wire Diameter": 1, "Name": "Winding", "Outer Radius": 52.75, "Inner Radius": 17.25, "Coil Pit(deg)": 1.828, "Occupation(%)": 45.7, "Height": 25.5}, "Layer Type": {"Separate": true, "Linked": false}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Number of Windings": {"1": false, "2": false, "3": false, "4": true}, "Layer": {"Simple": false, "Double": false, "Triple": true}, "Layer Type": {"Separate": false, "Linked": true}, "Similar Layer": {"Similar": false, "Different": true}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Hexagon": false, "Octagon": true, "Circle": false}, "Core": {"Name": "Core", "Inner Radius": 20, "Outer Radius": 50, "Height": 20, "Chamfer": 0.8}, "Outer Winding": {"Name": "Winding", "Inner Radius": 16.7, "Outer Radius": 53.3, "Height": 26.6, "Wire Diameter": 1.2, "Turns": 1, "Coil Pit(deg)": 2.265, "Occupation(%)": 5.033333333333333}, "Mid Winding": {"Turns": 3, "Coil Pit(deg)": 2.099, "Occupation(%)": 13.993333333333334}, "Inner Winding": {"Turns": 4, "Coil Pit(deg)": 1.956, "Occupation(%)": 17.386666666666667}}
1+
{"Mid Winding": {"Turns": 3, "Coil Pit(deg)": 2.099, "Occupation(%)": 13.993333333333334}, "Layer": {"Double": false, "Simple": false, "Triple": true}, "Number of Windings": {"4": true, "1": false, "3": false, "2": false}, "Similar Layer": {"Different": true, "Similar": false}, "Inner Winding": {"Turns": 4, "Coil Pit(deg)": 1.956, "Occupation(%)": 17.386666666666667}, "Mode": {"Differential": true, "Common": false}, "Wire Section": {"None": false, "Circle": false, "Octagon": true, "Hexagon": false}, "Outer Winding": {"Turns": 1, "Wire Diameter": 1.2, "Name": "Winding", "Outer Radius": 53.3, "Inner Radius": 16.7, "Coil Pit(deg)": 2.265, "Occupation(%)": 5.033333333333333, "Height": 26.6}, "Layer Type": {"Separate": false, "Linked": true}, "Core": {"Name": "Core", "Outer Radius": 50, "Inner Radius": 20, "Chamfer": 0.80000000000000004, "Height": 20}}

_unittest/test_00_EDB.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,22 @@
77
# Import required modules
88
from pyaedt import Edb
99
from pyaedt.edb_core.components import resistor_value_parser
10-
from pyaedt.generic.filesystem import Scratch
1110

1211

1312
test_project_name = "Galileo_edb"
1413
bom_example = "bom_example.csv"
15-
from _unittest.conftest import config, desktop_version, local_path, scratch_path, is_ironpython, settings
14+
from _unittest.conftest import config, desktop_version, local_path, scratch_path, is_ironpython, settings, BasisTest
1615

1716
try:
1817
import pytest
1918
except ImportError:
2019
import _unittest_ironpython.conf_unittest as pytest
2120

2221

23-
class TestClass:
22+
class TestClass(BasisTest, object):
2423
def setup_class(self):
25-
with Scratch(scratch_path) as self.local_scratch:
26-
# example_project = os.path.join(local_path, 'example_models', test_project_name + '.aedt')
27-
# self.test_project = self.local_scratch.copyfile(example_project)
28-
aedbproject = os.path.join(self.local_scratch.path, test_project_name + ".aedb")
29-
self.local_scratch.copyfolder(
30-
os.path.join(local_path, "example_models", test_project_name + ".aedb"),
31-
os.path.join(self.local_scratch.path, test_project_name + ".aedb"),
32-
)
33-
self.edbapp = Edb(
34-
os.path.join(self.local_scratch.path, test_project_name + ".aedb"),
35-
"Galileo_G87173_204",
36-
edbversion=desktop_version,
37-
isreadonly=False,
38-
)
24+
BasisTest.my_setup(self)
25+
self.edbapp = BasisTest.add_edb(self, test_project_name)
3926

4027
def teardown_class(self):
4128
self.edbapp.close_edb()
@@ -208,7 +195,7 @@ def test_17_components(self):
208195
assert self.edbapp.core_components.components["R1"].placement_layer
209196
assert isinstance(self.edbapp.core_components.components["R1"].lower_elevation, float)
210197
assert isinstance(self.edbapp.core_components.components["R1"].upper_elevation, float)
211-
assert self.edbapp.core_components.components["R1"].top_bottom_association == 1
198+
assert self.edbapp.core_components.components["R1"].top_bottom_association == 0
212199
assert self.edbapp.core_components.components["R1"].pinlist
213200
pinname = self.edbapp.core_components.components["R1"].pinlist[0].GetName()
214201
assert (

0 commit comments

Comments
 (0)