def test_return_values_dict(): """ Tests the return_all_values function in the HeartRateMonitor class """ try: import pytest from hrm.heart_rate_monitor import HeartRateMonitor from datetime import date except ImportError as e: print("necessary import failed: {}".format(e)) return test = HeartRateMonitor("tests/basic_test2.csv", mean_hr_bpm=6, data=[0], voltage_extremes=(2, 3), duration=4, num_beats=5, beats=[6], units='minute') ret = test.return_values_dict() values = { "mean_hr_bpm": test.mean_hr_bpm, "duration": test.duration, "units": test.units, "voltage_extremes": test.voltage_extremes, "num_beats": test.num_beats, "beats": test.beats } assert ret == values
def test_write_json(): """ Tests the write_json function in the HeartRateMonitor class """ try: import pytest from hrm.heart_rate_monitor import HeartRateMonitor from datetime import date import json except ImportError as e: print("Necessary import failed: {}".format(e)) return test = HeartRateMonitor("tests/basic_test2.csv", mean_hr_bpm=6, data=[0], voltage_extremes=(2, 3), duration=4, num_beats=5, beats=[6], units='minute') test.write_json() data = json.load(open('tests/basic_test2.json')) values = { "mean_hr_bpm": test.mean_hr_bpm, "duration": test.duration, "units": test.units, "voltage_extremes": list(test.voltage_extremes), "num_beats": test.num_beats, "beats": test.beats } assert data == values
def test_find_beats(): """ Tests the find_beats function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test1 = HeartRateMonitor("test_data/test_data1.csv") test1.find_beats()
def test_heart_rate(): """ Tests the find_heart_rate function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test1 = HeartRateMonitor("test_data/test_data1.csv") test1.find_heart_rate() assert int(test1.mean_hr_bpm) == int(35 * (60 / test1.duration))
def test_find_extreme_voltages(): """ Tests the find_extreme_voltages function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test = HeartRateMonitor("tests/basic_test2.csv") test.find_extreme_voltages() assert test.voltage_extremes == (1.0, 4.0)
def test_return_times(): """ Tests return_times function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test = HeartRateMonitor("tests/basic_test2.csv") res = test.return_times() assert np.array_equal(res, np.array([0.0, 1.0, 3.0]))
def test_graph_data(): """ Tests graph_data function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return for num in range(1, 4): test = HeartRateMonitor("test_data/test_data{}.csv".format(num)) res = test.graph_data(show=False) assert res is True
def test_calculate_all_values(): """ Runs the calculate_all_values function on every CSV file in the test_data directory to identity any exceptions raised """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return for num in range(1, 33): test = HeartRateMonitor("test_data/test_data{}.csv".format(num)) assert test.calculate_all_values() is True assert test.num_beats == test.beats.size
def test_find_heart_rates_for_interval(): """ Tests the find_heart_rates_for_interval function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test1 = HeartRateMonitor("test_data/test_data1.csv") ret1 = test1.find_heart_rates_for_interval(1) assert len(ret1) == 1 ret2 = test1.find_heart_rates_for_interval(0.4) assert len(ret2) == 2
def test_num_beats(): """ Tests the find_num_beats function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return beats = np.array([1, 2, 3, 4]) test1 = HeartRateMonitor("test_data/test_data1.csv", beats=beats) test1.find_num_beats() assert test1.num_beats == 4 test2 = HeartRateMonitor("test_data/test_data1.csv") test2.find_beats() test2.find_num_beats() assert test2.num_beats == 35
def test_find_duration(): """ Tests the find_duration function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test = HeartRateMonitor("tests/basic_test2.csv") assert test.duration == 3
def test_HeartRateMonitor_init(): """ Tests the init function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor except ImportError as e: print("Necessary import failed: {}".format(e)) return test1 = HeartRateMonitor("tests/basic_test2.csv", data=[1]) test2 = HeartRateMonitor("tests/basic_test2.csv", data=[2]) test3 = HeartRateMonitor("tests/basic_test2.csv", 6, [0], 1, (2, 3), 4, 5, [6], 'minute') assert test1.num_entries == 2 assert test1.data == [1] assert test1.mean_hr_bpm is None assert test1.voltage_extremes is None assert test1.duration == 1 assert test1.num_beats is None assert test1.beats is None assert test1.units == 'second' assert test2.num_entries is 2 assert test2.data == [2] assert test2.mean_hr_bpm is None assert test2.voltage_extremes is None assert test2.duration == 2 assert test2.num_beats is None assert test2.beats is None assert test2.units == 'second' assert test3.num_entries == 6 assert test3.data == [0] assert test3.mean_hr_bpm == 1 assert test3.voltage_extremes == (2, 3) assert test3.duration == 4 assert test3.num_beats == 5 assert test3.beats == [6] assert test3.units == 'minute'
def test_read_file(): """ Tests the read_file function in the HeartRateMonitor class """ try: import pytest import numpy as np from hrm.heart_rate_monitor import HeartRateMonitor from hrm.hrm_errors import EmptyFileError, FileFormatError except ImportError as e: print("Necessary import failed: {}".format(e)) return with pytest.raises(FileNotFoundError): test1 = HeartRateMonitor("missing.csv") with pytest.raises(EmptyFileError): test2 = HeartRateMonitor("tests/basic_test1.csv") with pytest.raises(FileFormatError): test2 = HeartRateMonitor("tests/basic_test2.csv", num_entries=3) with pytest.raises(FileFormatError): test3 = HeartRateMonitor("requirements.txt", num_entries=3) test4 = HeartRateMonitor("tests/basic_test2.csv") ans4 = np.array([[0, 1], [1, 2], [3, 4]]) assert np.array_equal(test4.data, ans4)