Skip to content

Commit 54f31dd

Browse files
authored
Adding automated testing capabilities (#20)
* fixed CI location * update language to UTF-8 for CI test * remove python version and update seabed tools to close file * edit cable props names everywhere * remove a bunch of dependencies * Update test input file locs, remove printout * removed plt.show() from example and pytest to run with github actions
1 parent 4dc83df commit 54f31dd

File tree

8 files changed

+55
-41
lines changed

8 files changed

+55
-41
lines changed

examples/example_driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#%% Section 1: Project without RAFT
3131
print('Creating project without RAFT\n')
32+
print(os.getcwd())
3233
# create project object
3334
project = Project(file=ontology_file,raft=False)
3435
# create moorpy system of the array, include cables in the system
@@ -42,7 +43,7 @@
4243
#create project object, automatically create RAFT object (and automatically create moorpy system in the process!)
4344
project = Project(file=ontology_file,raft=True)
4445
# plot in 3d, use moorpy system for mooring and cables, use RAFT for platform, tower, and turbine visuals
45-
project.plot3d(fowt=True,draw_boundary=False,boundary_on_bath=False)
46+
project.plot3d(fowt=True,draw_boundary=False,boundary_on_bath=False,save=True)
4647

4748
# get location of RAFT model (stored as array property in project class)
4849
model = project.array
@@ -111,7 +112,6 @@
111112
print('\nPristine line polyester nominal diameter just below surface: ',reg_line_d)
112113
print('Marine growth line polyester nominal diameter just below surface: ',mg_line_d)
113114

114-
plt.show()
115115

116116

117117

famodel-env.yaml

-1.93 KB
Binary file not shown.

famodel/cables/cable_properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def loadCableProps(source):
3131
elif source is None or source=="default":
3232
import os
3333
dir = os.path.dirname(os.path.realpath(__file__))
34-
with open(os.path.join(dir,"CableProps_default.yaml")) as file:
34+
with open(os.path.join(dir,"cableProps_default.yaml")) as file:
3535
source = yaml.load(file, Loader=yaml.FullLoader)
3636

3737
elif type(source) is str:
@@ -172,7 +172,7 @@ def loadBuoyProps(source):
172172
elif source is None or source=="default":
173173
import os
174174
dir = os.path.dirname(os.path.realpath(__file__))
175-
with open(os.path.join(dir,"CableProps_default.yaml")) as file:
175+
with open(os.path.join(dir,"cableProps_default.yaml")) as file:
176176
source = yaml.load(file, Loader=yaml.FullLoader)
177177

178178
elif type(source) is str:
@@ -267,7 +267,7 @@ def getBuoyProps(V, buoy_type, buoyProps=None, source=None, name="", rho=1025.0,
267267

268268
if __name__ == '__main__':
269269

270-
cableProps = loadCableProps('CableProps_default.yaml')
270+
cableProps = loadCableProps('cableProps_default.yaml')
271271

272272
As = [95,120, 150, 185, 200, 300, 400, 500, 630, 800]
273273

famodel/seabed/seabed_tools.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212

1313
def readBathymetryFile(filename, dtype=float):
1414

15-
f = open(filename, 'r')
16-
# skip the header
17-
line = next(f)
18-
# collect the number of grid values in the x and y directions from the second and third lines
19-
line = next(f)
20-
nGridX = int(line.split()[1])
21-
line = next(f)
22-
nGridY = int(line.split()[1])
23-
# allocate the Xs, Ys, and main bathymetry grid arrays
24-
bathGrid_Xs = np.zeros(nGridX)
25-
bathGrid_Ys = np.zeros(nGridY)
26-
bathGrid = np.zeros([nGridY, nGridX], dtype=dtype) # MH swapped order June 30
27-
# read in the fourth line to the Xs array
28-
line = next(f)
29-
bathGrid_Xs = [float(line.split()[i]) for i in range(nGridX)]
30-
strlist = []
31-
# read in the remaining lines in the file into the Ys array (first entry) and the main bathymetry grid
32-
for i in range(nGridY):
15+
with open(filename, 'r') as f:
16+
# skip the header
17+
line = next(f)
18+
# collect the number of grid values in the x and y directions from the second and third lines
19+
line = next(f)
20+
nGridX = int(line.split()[1])
3321
line = next(f)
34-
entries = line.split()
35-
bathGrid_Ys[i] = entries[0]
36-
if dtype==float:
37-
bathGrid[i,:] = entries[1:]
22+
nGridY = int(line.split()[1])
23+
# allocate the Xs, Ys, and main bathymetry grid arrays
24+
bathGrid_Xs = np.zeros(nGridX)
25+
bathGrid_Ys = np.zeros(nGridY)
26+
bathGrid = np.zeros([nGridY, nGridX], dtype=dtype) # MH swapped order June 30
27+
# read in the fourth line to the Xs array
28+
line = next(f)
29+
bathGrid_Xs = [float(line.split()[i]) for i in range(nGridX)]
30+
strlist = []
31+
# read in the remaining lines in the file into the Ys array (first entry) and the main bathymetry grid
32+
for i in range(nGridY):
33+
line = next(f)
34+
entries = line.split()
35+
bathGrid_Ys[i] = entries[0]
36+
if dtype==float:
37+
bathGrid[i,:] = entries[1:]
38+
if dtype==str:
39+
strlist.append(entries[1:])
3840
if dtype==str:
39-
strlist.append(entries[1:])
40-
if dtype==str:
41-
bathGrid = np.array(strlist)
41+
bathGrid = np.array(strlist)
4242

4343
return bathGrid_Xs, bathGrid_Ys, bathGrid
4444

tests/test_anchors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# tests anchor capacity and load functionality
22
from famodel.project import Project
33
import numpy as np
4+
import os
45

56

67
def test_anchor_loads():
78
# load in famodel project
8-
project = Project(file='tests/testOntology.yaml', raft=False)
9+
dir = os.path.dirname(os.path.realpath(__file__))
10+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
911
project.getMoorPyArray(cables=1)
1012
anch = project.anchorList['FOWT1a']
1113

@@ -18,7 +20,8 @@ def test_anchor_loads():
1820

1921
def test_anchor_capacities():
2022
# load in famodel project (suction pile anchor)
21-
project = Project(file='tests/testOntology.yaml', raft=False)
23+
dir = os.path.dirname(os.path.realpath(__file__))
24+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
2225
project.getMoorPyArray(cables=1)
2326
anch = project.anchorList['FOWT1a']
2427

tests/test_integrations.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313

1414
from famodel.mooring.mooring import Mooring
1515

16+
import os
17+
1618

1719
def test_MoorPy_integration():
18-
project = Project(file='tests/testOntology.yaml',raft=0)
20+
dir = os.path.dirname(os.path.realpath(__file__))
21+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
1922
project.getMoorPyArray(cables=1,plt=1)
2023
# check a random mooring line for ss
2124
assert project.mooringList['FOWT1a'].ss is not None
2225

2326
def test_RAFT_integration():
24-
project = Project(file='tests/testOntology.yaml')
27+
dir = os.path.dirname(os.path.realpath(__file__))
28+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=True)
2529
assert project.array is not None
2630

2731
'''def test_FLORIS_integration():'''

tests/test_project.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from famodel.cables.components import Joint
2424
from famodel.turbine.turbine import Turbine
2525

26+
import os
27+
2628
"""
2729
2830
def test_tensions_swap():
@@ -52,7 +54,8 @@ def test_bathymetry():
5254
project = Project()
5355

5456
# load bathymetry file (MoorDyn style)
55-
project.loadBathymetry('tests/bathymetry_sample.txt')
57+
dir = os.path.dirname(os.path.realpath(__file__))
58+
project.loadBathymetry(os.path.join(dir,'bathymetry_sample.txt'))
5659

5760
# sample the depth somewhere
5861
x=20
@@ -62,10 +65,10 @@ def test_bathymetry():
6265

6366
# plot to see if it worked
6467
#project.plot3d()
65-
plt.show()
6668

6769
def test_create_components():
68-
project = Project(file='tests/testOntology.yaml',raft=0)
70+
dir = os.path.dirname(os.path.realpath(__file__))
71+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
6972

7073
# check number of mooring lines
7174
assert len(project.mooringList) == 11
@@ -83,7 +86,8 @@ def test_create_components():
8386
assert len(project.platformList) == 4
8487

8588
def test_check_connections():
86-
project = Project(file='tests/testOntology.yaml',raft=0)
89+
dir = os.path.dirname(os.path.realpath(__file__))
90+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
8791
# check connections
8892
for i,anch in enumerate(project.anchorList.values()):
8993

@@ -109,15 +113,17 @@ def test_check_connections():
109113
assert len(pf.attachments) == 6 # 3 lines, 1 turbine, 2 cables
110114

111115
def test_headings_repositioning():
112-
project = Project(file='tests/testOntology.yaml',raft=0)
116+
dir = os.path.dirname(os.path.realpath(__file__))
117+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
113118
# check angles and repositioning for regular mooring line and shared mooring line, reg cable and suspended cable
114119
assert_allclose(np.hstack((project.mooringList['FOWT1a'].rA,project.mooringList['FOWT1-FOWT2'].rA)),
115120
np.hstack(([-828.637,-828.637,-600],[40.5,0,-20])),rtol=0,atol=0.5)
116121
assert_allclose(np.hstack((project.cableList['array_cable12'].subcomponents[0].rB,project.cableList['cable0'].subcomponents[0].rB)),
117122
np.hstack(([605,0,-600],[0,1615.5,-20])),rtol=0,atol=0.5)
118123

119124
def test_marine_growth():
120-
project = Project(file='tests/testOntology.yaml',raft=0)
125+
dir = os.path.dirname(os.path.realpath(__file__))
126+
project = Project(file=os.path.join(dir,'testOntology.yaml'), raft=False)
121127
# check correct mg gets added to specified mooring lines and cables for ss_mod
122128
project.getMarineGrowth(lines=['FOWT1a',['cable0',0]])
123129
# pull out a mooring line and a cable to check
@@ -133,7 +139,8 @@ def test_seabed():
133139
'''test seabed properties are properly loaded from a file'''
134140
# check soil at a location
135141
project = Project()
136-
project.loadSoil(filename='tests/soil_sample.txt')
142+
dir = os.path.dirname(os.path.realpath(__file__))
143+
project.loadSoil(filename=os.path.join(dir,'soil_sample.txt'))
137144
soilInfo = project.getSoilAtLocation(-828.637,-828.637)
138145
assert soilInfo[0] == 'mud_soft'
139146
assert soilInfo[1]['Su0'] == 2.39

0 commit comments

Comments
 (0)