Skip to content

Commit

Permalink
Fixed problems with tests and mypy, so that everything can be include…
Browse files Browse the repository at this point in the history
…d in the pipeline
  • Loading branch information
eisDNV committed Nov 4, 2024
1 parent 1a32b1a commit 8a288b4
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion case_study/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def update_namespace(sym: dict):
@staticmethod
def vector(x: tuple | list):
assert isinstance(x, (tuple, list)) and len(x) == 3, f"Vector of length 3 expected. Found {x}"
return x[0] * Assertion.N.i + x[1] * Assertion.N.j + x[2] * Assertion.N.k
return x[0] * Assertion.N.i + x[1] * Assertion.N.j + x[2] * Assertion.N.k # type: ignore

def assert_single(self, subs: list[tuple]):
"""Perform assertion on a single data point.
Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall0/results_base.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'base',
dateTime : '2024-11-04T09:28:08.129070',
dateTime : '2024-11-04T11:44:30.119146',
cases : 'BouncingBall',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-04T09:04:34.407987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-03T22:37:08.285872',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall0/results_gravity.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'gravity',
dateTime : '2024-11-04T09:28:16.053566',
dateTime : '2024-11-04T11:44:35.921661',
cases : 'BouncingBall',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-04T09:04:34.407987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-03T22:37:08.285872',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall0/results_restitution.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'restitution',
dateTime : '2024-11-04T09:28:12.628607',
dateTime : '2024-11-04T11:44:33.311249',
cases : 'BouncingBall',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-04T09:04:34.407987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-03T22:37:08.285872',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall0/results_restitutionAndGravity.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'restitutionAndGravity',
dateTime : '2024-11-04T09:28:19.217255',
dateTime : '2024-11-04T11:44:38.563853',
cases : 'BouncingBall',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-04T09:04:34.407987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall0/BouncingBall.cases',
casesDate : '2024-11-03T22:37:08.285872',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall3D/base.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'base',
dateTime : '2024-11-04T09:27:57.555042',
dateTime : '2024-11-04T11:44:08.031425',
cases : 'BouncingBall3D',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-04T09:04:34.413987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-03T21:49:56.360601',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall3D/gravity.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'gravity',
dateTime : '2024-11-04T09:27:59.101789',
dateTime : '2024-11-04T11:44:09.197116',
cases : 'BouncingBall3D',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-04T09:04:34.413987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-03T21:49:56.360601',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall3D/restitution.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'restitution',
dateTime : '2024-11-04T09:27:58.439740',
dateTime : '2024-11-04T11:44:08.628354',
cases : 'BouncingBall3D',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-04T09:04:34.413987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-03T21:49:56.360601',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/BouncingBall3D/restitutionAndGravity.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'restitutionAndGravity',
dateTime : '2024-11-04T09:27:59.673486',
dateTime : '2024-11-04T11:44:09.695343',
cases : 'BouncingBall3D',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-04T09:04:34.413987',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/BouncingBall3D/BouncingBall3D.cases',
casesDate : '2024-11-03T21:49:56.360601',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
6 changes: 3 additions & 3 deletions tests/data/MobileCrane/results_base.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'base',
dateTime : '2024-11-04T09:28:27.872834',
dateTime : '2024-11-04T11:44:45.704941',
cases : 'MobileCrane',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/MobileCrane/MobileCrane.cases',
casesDate : '2024-11-04T09:04:34.519986',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/MobileCrane/MobileCrane.cases',
casesDate : '2024-11-03T07:06:17.942318',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down
36 changes: 18 additions & 18 deletions tests/data/MobileCrane/results_static.js5
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
header : {
case : 'static',
dateTime : '2024-11-04T09:28:28.863301',
dateTime : '2024-11-04T11:44:46.599591',
cases : 'MobileCrane',
file : 'C:/Users/JORMEN/Documents/SeaCo/case_study/tests/data/MobileCrane/MobileCrane.cases',
casesDate : '2024-11-04T09:04:34.519986',
file : 'C:/Users/eis/Documents/Projects/Simulation_Model_Assurance/case_study/tests/data/MobileCrane/MobileCrane.cases',
casesDate : '2024-11-03T07:06:17.942318',
timeUnit : 'second',
timeFactor : 1000000000.0},

Expand Down Expand Up @@ -40,7 +40,7 @@ header : {

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.6146192678641134,0.0016706887455432758,4.191560790727376]}},
x_load : [3.6146192678641125,0.001670688745543276,4.191560790727377]}},

0.3 : {
mobileCrane : {
Expand All @@ -50,37 +50,37 @@ header : {

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.6098303267689977,0.0016725131777828876,4.189097289389069]}},
x_load : [3.6098303267689964,0.0016725131777828855,4.189097289389067]}},

0.4 : {
mobileCrane : {
T : [-79102.14146566678,-84513.17367630609,494.14998034099153],
T : [-79102.14146566749,-84513.17367630739,494.14998034116917],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.6050235454165396,0.0016743444065856676,4.186628891795709]}},
x_load : [3.6050235454165374,0.0016743444065856628,4.186628891795709]}},

0.5 : {
mobileCrane : {
T : [-79092.99117590865,-81131.3725644038,484.925063439427],
T : [-79092.99117590723,-81131.37256440127,484.92506343907155],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.6002104179888765,0.0016761780530386073,4.184161528165493]}},
x_load : [3.6002104179888765,0.0016761780530385995,4.184161528165493]}},

0.6 : {
mobileCrane : {
T : [-79084.0743735005,-77759.14002690287,475.8363028297221],
T : [-79084.07437350121,-77759.1400269041,475.8363028298998],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.5953966336481056,0.0016780119497542727,4.181698119653884]}},
x_load : [3.5953966336481056,0.0016780119497542634,4.181698119653884]}},

0.7 : {
mobileCrane : {
Expand All @@ -90,34 +90,34 @@ header : {

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.5905850090110265,0.0016798450236924227,4.179240100981307]}},
x_load : [3.590585009011029,0.0016798450236924119,4.179240100981308]}},

0.8 : {
mobileCrane : {
T : [-79067.06582688275,-71044.28346353743,458.3500633802192],
T : [-79067.06582688275,-71044.28346353714,458.3500633801303],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.5857769392348664,0.0016816767433431154,4.176788172608904]}},
x_load : [3.585776939234872,0.0016816767433431034,4.176788172608907]}},

0.9 : {
mobileCrane : {
T : [-79058.9708401786,-67701.668534116,449.9665547836707],
T : [-79058.9708401786,-67701.66853411475,449.96655478331536],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.580973116066061,0.0016835068451732465,4.174342672302927]}},
x_load : [3.580973116066073,0.0016835068451732328,4.174342672302934]}},

1.0 : {
mobileCrane : {
T : [-79051.13567116468,-64368.86008482016,441.8103059741506],
T : [-79051.13567116397,-64368.86008482007,441.81030597432846],

x_pedestal : [0.0,0.0,3.0],

x_boom : [0.10961760610884069,0.003005981434384228,10.999248398725133],

x_load : [3.5761738831569434,0.0016853351982623515,4.171903758680079]}}}
x_load : [3.5761738831569576,0.0016853351982623363,4.171903758680086]}}}
11 changes: 5 additions & 6 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from case_study.case import Cases, Results


@pytest.mark.skip(reason="File contains harcoded absolute path")
def test_init():
# init through existing results file
file = Path.cwd().parent / "data" / "BouncingBall3D" / "test_results.js5"
file = Path(__file__).parent / "data" / "BouncingBall3D" / "test_results.js5"
print("FILE", file)
res = Results(file=file)
assert res.res.jspath("$.header.file", Path, True).exists()
Expand All @@ -34,12 +33,12 @@ def test_add():
assert res.res.jspath("$['0.0'].bb.g") == 9.81


@pytest.mark.skip(reason="Plots cannot be tested in CI")
def test_plot_time_series():
def test_plot_time_series( show):
file = Path(__file__).parent / "data" / "BouncingBall3D" / "test_results.js5"
assert file.exists(), f"File {file} not found"
res = Results(file=file)
res.plot_time_series(("bb.x[2]", "bb.v[2]"), "Test plot")
if show:
res.plot_time_series(("bb.x[2]", "bb.v[2]"), "Test plot")


def test_inspect():
Expand All @@ -57,7 +56,7 @@ def test_inspect():


if __name__ == "__main__":
retcode = pytest.main(["-rA", "-v", __file__])
retcode = pytest.main(["-rA", "-v", __file__, "--show", "True"])
assert retcode == 0, f"Non-zero return code {retcode}"
# import os
# os.chdir(Path(__file__).parent.absolute() / "test_working_directory")
Expand Down

0 comments on commit 8a288b4

Please sign in to comment.