Skip to content

Commit

Permalink
Forcing to show current directory of
Browse files Browse the repository at this point in the history
  • Loading branch information
pariterre committed Feb 7, 2024
1 parent 4bb5ae2 commit 67cf68e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 105 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/run_frontend_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
- run: flutter frontend/test

- name: Run tests
run: |
cd frontend
flutter test
2 changes: 1 addition & 1 deletion .github/workflows/run_server_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run server tests
on: [pull_request]

env:
PYTHON_PATH: ../external/pyScienceMode/
PYTHON_PATH: ./server/external/pyScienceMode/

jobs:
build:
Expand Down
217 changes: 114 additions & 103 deletions server/tests/test_common_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,139 +2,150 @@
import os
import pickle

import numpy as np

from lokomat_fes import Data
from lokomat_fes.nidaq.data import NiDaqData
from lokomat_fes.rehastim.data import RehastimData, Channel
def test_tata():
print("coucou")
print(os.getcwd())
# show python_path environment variable
print(os.environ["PYTHONPATH"])

print("coucou")
raise Exception(f"{os.getcwd()}")


# Print current working directory to the console
print("coucou")
print(os.getcwd())
print("coucou")

import numpy as np

# from lokomat_fes import Data
# from lokomat_fes.nidaq.data import NiDaqData
# from lokomat_fes.rehastim.data import RehastimData, Channel

def test_data_creation():
data = Data()
assert isinstance(data.nidaq, NiDaqData)
assert isinstance(data.rehastim, RehastimData)
assert data.nidaq.t0 == data.t0
assert data.rehastim.t0 == data.t0

# def test_data_creation():
# data = Data()
# assert isinstance(data.nidaq, NiDaqData)
# assert isinstance(data.rehastim, RehastimData)
# assert data.nidaq.t0 == data.t0
# assert data.rehastim.t0 == data.t0

def test_add_nidaq_data():
data = Data()

# Add data
data.nidaq.add(np.array([1]), np.array([[2]]))
# def test_add_nidaq_data():
# data = Data()

# Check that the data exists
assert data.nidaq.t0.timestamp() is not None
assert data.nidaq.time is not None
assert data.nidaq.as_array is not None
# # Add data
# data.nidaq.add(np.array([1]), np.array([[2]]))

# # Check that the data exists
# assert data.nidaq.t0.timestamp() is not None
# assert data.nidaq.time is not None
# assert data.nidaq.as_array is not None

def test_add_rehastim_data():
data = Data()

# Add data
data.rehastim.add(
now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
)
# def test_add_rehastim_data():
# data = Data()

# Check that the data exists
assert data.rehastim.time is not None
np.testing.assert_almost_equal(data.rehastim.duration_as_array, np.array([1]))
assert data.rehastim.duration_as_array is not None
np.testing.assert_almost_equal(data.rehastim.duration_as_array, np.array([1]))
assert data.rehastim.amplitude_as_array is not None
np.testing.assert_almost_equal(data.rehastim.amplitude_as_array, np.array([[2, 4]]).T)
# # Add data
# data.rehastim.add(
# now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
# )

# # Check that the data exists
# assert data.rehastim.time is not None
# np.testing.assert_almost_equal(data.rehastim.duration_as_array, np.array([1]))
# assert data.rehastim.duration_as_array is not None
# np.testing.assert_almost_equal(data.rehastim.duration_as_array, np.array([1]))
# assert data.rehastim.amplitude_as_array is not None
# np.testing.assert_almost_equal(data.rehastim.amplitude_as_array, np.array([[2, 4]]).T)

def test_copy_data():
data = Data()

# Add data
data.nidaq.add(np.array([1]), np.array([[2]]))
data.rehastim.add(
now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
)
# def test_copy_data():
# data = Data()

# Copy the data
data_copy = data.copy
# # Add data
# data.nidaq.add(np.array([1]), np.array([[2]]))
# data.rehastim.add(
# now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
# )

# Check that the data is correct
assert data_copy.nidaq.t0 == data.nidaq.t0
np.testing.assert_almost_equal(data_copy.nidaq.time, data.nidaq.time)
np.testing.assert_almost_equal(data_copy.nidaq.as_array, data.nidaq.as_array)
np.testing.assert_almost_equal(data_copy.rehastim.time, data.rehastim.time)
np.testing.assert_almost_equal(data_copy.rehastim.duration_as_array, data.rehastim.duration_as_array)
np.testing.assert_almost_equal(data_copy.rehastim.amplitude_as_array, data.rehastim.amplitude_as_array)
# # Copy the data
# data_copy = data.copy

# The copy is a deep copy
t, d = data_copy.nidaq.sample_block(0, unsafe=True)
t[0] = 0
d[0, 0] = 0
# # Check that the data is correct
# assert data_copy.nidaq.t0 == data.nidaq.t0
# np.testing.assert_almost_equal(data_copy.nidaq.time, data.nidaq.time)
# np.testing.assert_almost_equal(data_copy.nidaq.as_array, data.nidaq.as_array)
# np.testing.assert_almost_equal(data_copy.rehastim.time, data.rehastim.time)
# np.testing.assert_almost_equal(data_copy.rehastim.duration_as_array, data.rehastim.duration_as_array)
# np.testing.assert_almost_equal(data_copy.rehastim.amplitude_as_array, data.rehastim.amplitude_as_array)

t2, d2 = data_copy.nidaq.sample_block(0, unsafe=True)
t_orig, d_orig = data.nidaq.sample_block(0, unsafe=True)
np.testing.assert_almost_equal(t2[0], 0)
np.testing.assert_almost_equal(d2[0, 0], 0)
np.testing.assert_almost_equal(t_orig[0], 1)
np.testing.assert_almost_equal(d_orig[0], 2)
# # The copy is a deep copy
# t, d = data_copy.nidaq.sample_block(0, unsafe=True)
# t[0] = 0
# d[0, 0] = 0

# t2, d2 = data_copy.nidaq.sample_block(0, unsafe=True)
# t_orig, d_orig = data.nidaq.sample_block(0, unsafe=True)
# np.testing.assert_almost_equal(t2[0], 0)
# np.testing.assert_almost_equal(d2[0, 0], 0)
# np.testing.assert_almost_equal(t_orig[0], 1)
# np.testing.assert_almost_equal(d_orig[0], 2)

def test_serialize_data():
data = Data()

# Add data
data.nidaq.add(np.array([1]), np.array([[2]]))
data.rehastim.add(
now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
)
# def test_serialize_data():
# data = Data()

# Serialize the data for pickle
serialized_data = data.serialize()
assert pickle.dumps(serialized_data)
# # Add data
# data.nidaq.add(np.array([1]), np.array([[2]]))
# data.rehastim.add(
# now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
# )

# Check that the data is correct
assert serialized_data["t0"] == data.t0.timestamp()
assert serialized_data["nidaq"] == data.nidaq.serialize()
assert serialized_data["rehastim"] == data.rehastim.serialize()
# # Serialize the data for pickle
# serialized_data = data.serialize()
# assert pickle.dumps(serialized_data)

# Serialize the data for json
serialized_data = data.serialize(to_json=True)
assert json.dumps(serialized_data)
# # Check that the data is correct
# assert serialized_data["t0"] == data.t0.timestamp()
# assert serialized_data["nidaq"] == data.nidaq.serialize()
# assert serialized_data["rehastim"] == data.rehastim.serialize()

# Check that the data is correct
assert serialized_data["t0"] == data.t0.timestamp()
assert serialized_data["nidaq"] == data.nidaq.serialize(to_json=True)
assert serialized_data["rehastim"] == data.rehastim.serialize(to_json=True)
# # Serialize the data for json
# serialized_data = data.serialize(to_json=True)
# assert json.dumps(serialized_data)

# # Check that the data is correct
# assert serialized_data["t0"] == data.t0.timestamp()
# assert serialized_data["nidaq"] == data.nidaq.serialize(to_json=True)
# assert serialized_data["rehastim"] == data.rehastim.serialize(to_json=True)


def test_save_and_load():
data = Data()

# Add data
data.nidaq.add(np.array([1]), np.array([[2]]))
data.rehastim.add(
now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
)
# def test_save_and_load():
# data = Data()

# # Add data
# data.nidaq.add(np.array([1]), np.array([[2]]))
# data.rehastim.add(
# now=1, duration=1, channels=(Channel(channel_index=1, amplitude=2), Channel(channel_index=2, amplitude=4))
# )

# Save the data
path = "test_data.pkl"
data.save(path)

# Load the data
data_loaded = Data.load(path)

# Check that the data is correct
assert data_loaded.nidaq.t0 == data.nidaq.t0
np.testing.assert_almost_equal(data_loaded.nidaq.time, data.nidaq.time)
np.testing.assert_almost_equal(data_loaded.nidaq.as_array, data.nidaq.as_array)
np.testing.assert_almost_equal(data_loaded.rehastim.time, data.rehastim.time)
np.testing.assert_almost_equal(data_loaded.rehastim.duration_as_array, data.rehastim.duration_as_array)
np.testing.assert_almost_equal(data_loaded.rehastim.amplitude_as_array, data.rehastim.amplitude_as_array)

# Delete the file
os.remove(path)
# # Save the data
# path = "test_data.pkl"
# data.save(path)

# # Load the data
# data_loaded = Data.load(path)

# # Check that the data is correct
# assert data_loaded.nidaq.t0 == data.nidaq.t0
# np.testing.assert_almost_equal(data_loaded.nidaq.time, data.nidaq.time)
# np.testing.assert_almost_equal(data_loaded.nidaq.as_array, data.nidaq.as_array)
# np.testing.assert_almost_equal(data_loaded.rehastim.time, data.rehastim.time)
# np.testing.assert_almost_equal(data_loaded.rehastim.duration_as_array, data.rehastim.duration_as_array)
# np.testing.assert_almost_equal(data_loaded.rehastim.amplitude_as_array, data.rehastim.amplitude_as_array)

# # Delete the file
# os.remove(path)

0 comments on commit 67cf68e

Please sign in to comment.