Skip to content

Commit

Permalink
move test data types to annotations, na from conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
LoannPeurey committed Aug 1, 2024
1 parent d522cba commit e69ae02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 63 deletions.
25 changes: 25 additions & 0 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,31 @@ def test_multiple_imports(project, am, input_file, ow, rimported, rerrors, excep
assert len(errors) == 0 and len(warnings) == 0, "malformed annotation indexes detected"


def test_import_incorrect_data_types(project, am):
incorrect_types = pd.DataFrame({
"segment_onset": ["0", "10", "20"],
"segment_offset": ["5", "15", "25"],
"speaker_type": ["CHI", "FEM", "MAN"],
"time_since_last_conv": ["nan", "15", "5"],
"conv_count": [1, 1, 2]
})

with pytest.raises(Exception):
am.import_annotations(
pd.DataFrame(
[{"set": "incorrect_types_conv",
"raw_filename": "file.its",
"time_seek": 0,
"recording_filename": "sound.wav",
"range_onset": 0,
"range_offset": 30000000,
"format": "csv",
}]
),
import_function=partial(fake_vocs, incorrect_types),
)


# function used as a derivation function, it should throw errors if not returning dataframe or without required columns
def dv_func(a, b, x, type):
if type == 'number':
Expand Down
63 changes: 0 additions & 63 deletions tests/test_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,6 @@ def test_empty_conversations(project, am):
results = std.extract()

assert results.empty, "The result should be empty for an empty dataset"
def test_nan_values(project, am):
nan_segments = pd.DataFrame({
"segment_onset": [np.nan, 10, 20],
"segment_offset": [5, np.nan, 25],
"speaker_type": ["CHI", np.nan, "FEM"],
"time_since_last_conv": [np.nan, 15, 5],
"conv_count": [1, 1, 2]
})

am.import_annotations(
pd.DataFrame(
[{"set": "nan_conv",
"raw_filename": "file.its",
"time_seek": 0,
"recording_filename": "sound.wav",
"range_onset": 0,
"range_offset": 30000000,
"format": "csv",
}]
),
import_function=partial(fake_vocs, nan_segments),
)

std = StandardConversations(project, setname='nan_conv')
results = std.extract()

assert not results.empty, "The result should not be empty for a dataset with NaN values"


def test_single_entry_conversation(project, am):
Expand Down Expand Up @@ -285,34 +258,6 @@ def test_single_entry_conversation(project, am):
assert len(results) == 1, "The result should contain one conversation for a single entry dataset"


def test_incorrect_data_types(project, am):
incorrect_types = pd.DataFrame({
"segment_onset": ["0", "10", "20"],
"segment_offset": ["5", "15", "25"],
"speaker_type": ["CHI", "FEM", "MAN"],
"time_since_last_conv": ["nan", "15", "5"],
"conv_count": [1, 1, 2]
})

am.import_annotations(
pd.DataFrame(
[{"set": "incorrect_types_conv",
"raw_filename": "file.its",
"time_seek": 0,
"recording_filename": "sound.wav",
"range_onset": 0,
"range_offset": 30000000,
"format": "csv",
}]
),
import_function=partial(fake_vocs, incorrect_types),
)

std = StandardConversations(project, setname='incorrect_types_conv')
with pytest.raises(Exception):
std.extract(), "The code should raise an exception for incorrect data types"


def test_unsorted_annotations(project, am):
unsorted_segments = pd.DataFrame({
"segment_onset": [20, 0, 10],
Expand Down Expand Up @@ -340,11 +285,3 @@ def test_unsorted_annotations(project, am):
results = std.extract()

assert not results.empty, "The result should not be empty for unsorted annotations"


def test_all_cases(project, am, segments):
test_empty_conversations(project, am)
test_nan_values(project, am)
test_single_entry_conversation(project, am)
test_incorrect_data_types(project, am)
test_unsorted_annotations(project, am)

0 comments on commit e69ae02

Please sign in to comment.