Skip to content

Commit

Permalink
Remove warnings in tests. Mostly row index accesses.
Browse files Browse the repository at this point in the history
  • Loading branch information
rantahar committed Feb 20, 2024
1 parent 2cbe7f3 commit f48679b
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions tests/reading/test_read_mhealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_format_part_of_day():
}])
df = niimpy.reading.mhealth.format_part_of_day(df, "prefix.col")

assert df["date"][0] == pd.to_datetime("2022-01-14")
assert df["date"][0] == pd.to_datetime("2022-01-14 00:00:00+00:00")
assert df["part_of_day"][0] == "afternoon"


Expand All @@ -28,8 +28,8 @@ def test_duration_to_timedelta():

df = niimpy.reading.mhealth.duration_to_timedelta(df, "prefix.col")

assert df["prefix.col"][0] == pd.to_timedelta(20, unit="minutes")
assert df["prefix.col"][1] == pd.to_timedelta(0.02, unit="nanoseconds")
assert df.iloc[0]["prefix.col"] == pd.to_timedelta(20, unit="minutes")
assert df.iloc[1]["prefix.col"] == pd.to_timedelta(0.02, unit="nanoseconds")


def test_format_time_interval():
Expand Down Expand Up @@ -66,32 +66,41 @@ def test_format_time_interval():

def test_read_mhealth_total_sleep_time():
data = niimpy.reading.mhealth.total_sleep_time_from_file(config.MHEALTH_TOTAL_SLEEP_TIME_PATH)
assert data['total_sleep_time'][0] == pd.Timedelta(465, unit="minutes")
assert data['descriptive_statistic'][1] == "average"
assert data['descriptive_statistic_denominator'][1] == "d"
assert data['date'][3] == pd.to_datetime("2013-02-05")
assert data['part_of_day'][3] == "evening"
assert data['start'][0] == pd.to_datetime("2016-02-06 04:35:00+00:00")
assert data['end'][0] == pd.to_datetime("2016-02-06 14:35:00+00:00")
assert data['start'][2] == pd.to_datetime("2013-01-26 07:35:00+00:00")
assert data['end'][2] == pd.to_datetime("2013-02-05 07:35:00+00:00")

row = data.loc["2016-02-06 04:35:00+00:00"]
assert row['total_sleep_time'] == pd.Timedelta(465, unit="minutes")
assert row['start'] == pd.to_datetime("2016-02-06 04:35:00+00:00")
assert row['end'] == pd.to_datetime("2016-02-06 14:35:00+00:00")

row = data.loc["2016-02-05 15:00:00+00:00"]
assert row['descriptive_statistic'] == "average"
assert row['descriptive_statistic_denominator'] == "d"

row = data.loc["2013-01-26 07:35:00+00:00"]
assert row['start'] == pd.to_datetime("2013-01-26 07:35:00+00:00")
assert row['end'] == pd.to_datetime("2013-02-05 07:35:00+00:00")

part_of_day_row = data.iloc[3]
assert part_of_day_row['date'] == pd.to_datetime("2013-02-05", utc=True)
assert part_of_day_row['part_of_day'] == "evening"



def test_read_mhealth_heart_rate():
data = niimpy.reading.mhealth.heart_rate_from_file(config.MHEALTH_HEART_RATE_PATH)
assert data['heart_rate'][0] == 70
assert data['heart_rate'][1] == 65
assert data['descriptive_statistic'][2] == "average"
assert data['temporal_relationship_to_sleep'][2] == "during sleep"
assert data['temporal_relationship_to_sleep'][0] == "on waking"
assert data['start'][2] == pd.to_datetime("2023-12-20T01:50:00-02:00")
assert data.iloc[0]['heart_rate'] == 70
assert data.iloc[1]['heart_rate'] == 65
assert data.iloc[2]['descriptive_statistic'] == "average"
assert data.iloc[2]['temporal_relationship_to_sleep'] == "during sleep"
assert data.iloc[0]['temporal_relationship_to_sleep'] == "on waking"
assert data.iloc[2]['start'] == pd.to_datetime("2023-12-20T01:50:00-02:00")


def test_read_mhealth_geolocation():
data = niimpy.reading.mhealth.geolocation_from_file(config.MHEALTH_GEOLOCATION_PATH)

assert data['latitude'][0] == 60.1867
assert data['longitude'][0] == 24.8283
assert data['latitude'][1] == 60.1867
assert data['longitude'][1] == 24.8283
assert data.iloc[0]['latitude'] == 60.1867
assert data.iloc[0]['longitude'] == 24.8283
assert data.iloc[1]['latitude'] == 60.1867
assert data.iloc[1]['longitude'] == 24.8283

0 comments on commit f48679b

Please sign in to comment.