Skip to content

Commit

Permalink
Updated the actions, did test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
VisLab committed Sep 27, 2024
1 parent f36ecc5 commit c519f1b
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 223 deletions.
53 changes: 40 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('docs/requirements.txt') }}

# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade --upgrade-strategy eager pip
Expand All @@ -56,35 +57,61 @@ jobs:
pip install -r requirements.txt
pip install -r docs/requirements.txt
# Run flake8 only for Python 3.9
- name: Lint with flake8
if: matrix.python-version == '3.9'
run: |
pip install flake8
flake8 . --count --show-source --statistics --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with unittest
# Run unittest with coverage for Python 3.9
- name: Test with unittest and coverage (v3.9)
env:
HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ matrix.python-version }}" == "3.9" ]; then
if: matrix.python-version == '3.9'
run: |
pip install coverage
coverage run -m unittest discover tests
else
python -m unittest tests
fi
continue-on-error: true


- name: Run spec_test coverage
# Run unittest without coverage for non Python 3.9
- name: Test with unittest (non-3.9)
env:
HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.python-version != '3.9'
run: |
if ["${{ matrix.python-version }}" == "3.9" ]; then
coverage run --append -m unittest discover tests/spec_tests
ls -a
continue-on-error: true
if
python -m unittest discover tests
continue-on-error: true
# Run spec tests with coverage for Python 3.9
- name: Run spec_test coverage
env:
HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.python-version == '3.9'
run: |
coverage run --append -m unittest discover tests/spec_tests
ls -a
continue-on-error: true
# Run spec tests without coverage for non Python 3.9
- name: Run spec_test
env:
HED_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.python-version != '3.9'
run: |
python -m unittest discover tests/spec_tests
continue-on-error: true
- name: Archive code coverage results
# Archive code coverage results for Python 3.9
- name: Archive code coverage results for Python 3.9
if: ${{matrix.python-version == '3.9'}}
uses: actions/upload-artifact@v4
with:
Expand Down
30 changes: 23 additions & 7 deletions tests/tools/analysis/test_hed_tag_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,40 @@ def test_constructor_from_tabular_input(self):
tag_man1 = HedTagManager(EventManager(self.input_data, self.schema))
self.assertIsInstance(tag_man1, HedTagManager)
hed_objs1a = tag_man1.get_hed_objs(include_context=False, replace_defs=False)
self.assertNotIn('Event-context', str(hed_objs1a[1]))
self.assertIn('Def', str(hed_objs1a[1]))
self.assertNotIn('Condition-variable', str(hed_objs1a[1]))
hed_objs1b = tag_man1.get_hed_objs(include_context=True, replace_defs=False)
self.assertIn('Event-context', str(hed_objs1b[1]))
self.assertIn('Def', str(hed_objs1b[1]))
self.assertNotIn('Condition-variable', str(hed_objs1b[1]))
hed_objs1c = tag_man1.get_hed_objs(include_context=False, replace_defs=True)
self.assertNotIn('Event-context', str(hed_objs1c[1]))
self.assertNotIn('Def', str(hed_objs1c[1]))
self.assertIn('Condition-variable', str(hed_objs1c[1]))
hed_objs1d = tag_man1.get_hed_objs(include_context=True, replace_defs=True)
self.assertIn('Event-context', str(hed_objs1d[1]))
self.assertNotIn('Def', str(hed_objs1d[1]))
self.assertIn('Condition-variable', str(hed_objs1d[1]))
tag_man2 = HedTagManager(event_man, remove_types=['Condition-variable', 'Task'])
hed_objs2a = tag_man2.get_hed_objs(include_context=False, replace_defs=False)
self.assertNotIn('Condition-variable', str(hed_objs2a[1]))
hed_objs2b = tag_man2.get_hed_objs(include_context=True, replace_defs=False)
hed_objs1c = tag_man2.get_hed_objs(include_context=False, replace_defs=True)
hed_objs1d = tag_man2.get_hed_objs(include_context=True, replace_defs=True)
self.assertNotIn('Condition-variable', str(hed_objs2b[1]))
hed_objs2c = tag_man2.get_hed_objs(include_context=False, replace_defs=True)
self.assertNotIn('Condition-variable', str(hed_objs2c[1]))
hed_objs2d = tag_man2.get_hed_objs(include_context=True, replace_defs=True)
self.assertNotIn('Condition-variable', str(hed_objs2d[1]))
self.assertIsInstance(tag_man2, HedTagManager)
self.assertIsInstance(tag_man2, HedTagManager)

def test_get_hed_objs(self):
event_man = EventManager(self.input_data, self.schema)
tag_man1 = HedTagManager(EventManager(self.input_data, self.schema))
# tag_man = HedTagManager(event_man, remove_types=['Condition-variable', 'Task'])
# hed_objs = tag_man.get_hed_objs()
# self.assertIsInstance(hed_objs, list)
# self.assertEqual(len(hed_objs), len(event_man.onsets))
tag_man = HedTagManager(EventManager(self.input_data, self.schema))
self.assertIsInstance(tag_man, HedTagManager)
hed_objs = tag_man.get_hed_objs()
self.assertIsInstance(hed_objs, list)
self.assertEqual(len(hed_objs), len(event_man.onsets))

# def test_constructor_variable_caps(self):
# sidecar1 = Sidecar(self.sidecar_path, name='face_sub1_json')
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/analysis/test_hed_type_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def test_get_type_values(self):
item1 = HedString("Sensory-event,((Red,Blue)),", self.schema)
vars1 = def_man.get_type_values(item1)
self.assertFalse(vars1, "get_type_values should return None if no condition type_variables")
item2 = HedString(f"Sensory-event,(Def/Cond1,(Red,Blue,Condition-variable/Trouble))", self.schema)
item2 = HedString("Sensory-event,(Def/Cond1,(Red,Blue,Condition-variable/Trouble))", self.schema)
vars2 = def_man.get_type_values(item2)
self.assertEqual(1, len(vars2), "get_type_values should return correct number of condition type_variables")
item3 = HedString(f"Sensory-event,(Def/Cond1,(Red,Blue,Condition-variable/Trouble)),"
f"(Def/Cond2),Green,Yellow,Def/Cond5, Def/Cond6/4, Description/Tell me", self.schema)
item3 = HedString("Sensory-event,(Def/Cond1,(Red,Blue,Condition-variable/Trouble))," +
"(Def/Cond2),Green,Yellow,Def/Cond5, Def/Cond6/4, Description/Tell me", self.schema)
vars3 = def_man.get_type_values(item3)
self.assertEqual(len(vars3), 5, "get_type_values should return multiple condition type_variables")

Expand Down
2 changes: 1 addition & 1 deletion tests/tools/analysis/test_key_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_make_template(self):
self.assertEqual(len(df1.columns), 1, "make_template should return 1 column single key, no additional columns")
df2 = t_map.make_template(show_counts=True)
self.assertEqual(len(df2.columns), 2, "make_template returns an extra column for counts")

t_map2 = KeyMap(['event_type', 'type'])
t_map2.update(self.stern_test1_path)
df3 = t_map2.make_template()
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/analysis/test_sequence_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def setUpClass(cls):
'/sub-01/ses-01/eeg/sub-01_ses-01_task-DriveRandomSound_run-1_events.tsv')

def test_constructor(self):
codes1 = ['1111', '1112', '1121', '1122', '1131', '1132', '1141',
codes1 = ['1111', '1112', '1121', '1122', '1131', '1132', '1141',
'1142', '1311', '1312', '1321', '1322',
'4210', '4220', '4230', '4311', '4312']

smap1 = SequenceMap(codes=codes1)
self.assertIsInstance(smap1, SequenceMap)
# df = get_new_dataframe(self.events_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/bids/test_bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_validator_types(self):
def test_with_schema_group(self):
x = load_schema_version(["score_2.0.0", "test:testlib_1.0.2"])
bids = BidsDataset(self.library_path, schema=x, tabular_types=["participants"])
self.assertIsInstance(bids, BidsDataset,
self.assertIsInstance(bids, BidsDataset,
"BidsDataset with libraries should create a valid object from valid dataset")
parts = bids.get_tabular_group("participants")
self.assertIsInstance(parts, BidsFileGroup, "BidsDataset participants should be a BidsFileGroup")
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/remodeling/cli/test_run_remodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_parse_arguments(self):
with self.assertRaises(ValueError) as context3:
parse_arguments(arg_list3)
self.assertEqual(context3.exception.args[0], "UnableToFullyParseOperations")

def test_parse_tasks(self):
tasks1 = parse_tasks(self.files, "*")
self.assertIn('stopsignal', tasks1)
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/remodeling/operations/test_base_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestOp(BaseOp):

def do_op(self, dispatcher, df, name, sidecar=None):
return df

@staticmethod
def validate_input_data(parameters):
return []
Expand Down Expand Up @@ -61,7 +61,7 @@ class TestOpNoName(BaseOp):

def do_op(self, dispatcher, df, name, sidecar=None):
return df

with self.assertRaises(TypeError):
TestOpNoName({})

Expand Down
12 changes: 6 additions & 6 deletions tests/tools/remodeling/operations/test_number_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,25 @@ def test_number_groups_new_column(self):
# df_check = pd.DataFrame(self.numbered_data, columns=self.numbered_columns)
# df_test = pd.DataFrame(self.sample_data, columns=self.sample_columns)
# df_new = op.do_op(self.dispatcher, df_test, self.file_name)
#
#
# self.assertTrue(list(df_new.columns) == list(self.numbered_columns),
# "numbered_events should have the expected columns")
# self.assertTrue(len(df_new) == len(df_test),
# "numbered_events should have same length as original dataframe")
# self.assertTrue(np.nanmax(df_new["number"]) == 5.0,
# "max value in numbered_events should match the number of groups")
#
#
# # fill na to match postprocessing dispatcher
# df_new = df_new.fillna('n/a')
# self.assertTrue(np.array_equal(df_new.to_numpy(), df_check.to_numpy()),
# "numbered_events should not differ from check")
#
#
# # Test that df has not been changed by the op
# self.assertTrue(list(df.columns) == list(df_test.columns),
# "number_rows should not change the input df columns")
# self.assertTrue(np.array_equal(df.to_numpy(), df_test.to_numpy()),
# "number_rows should not change the input df values")
#
#
# def test_existing_column_overwrite_true(self):
# # Test when existing column name is given with overwrite True
# parms = json.loads(self.json_overwrite_true_parms)
Expand All @@ -185,7 +185,7 @@ def test_number_groups_new_column(self):
# df_test = pd.DataFrame(self.sample_data, columns=self.existing_sample_columns)
# df_check = pd.DataFrame(self.overwritten_data, columns=self.existing_sample_columns)
# df_new = op.do_op(self.dispatcher, df_test, self.file_name)
#
#
# self.assertTrue(list(df_new.columns) == list(self.existing_sample_columns),
# "numbered_events should have the same columns as original dataframe in case of overwrite")
# self.assertTrue(len(df_new) == len(df_test),
Expand All @@ -195,7 +195,7 @@ def test_number_groups_new_column(self):
# df_new = df_new.fillna('n/a')
# self.assertTrue(np.array_equal(df_new.to_numpy(), df_check.to_numpy()),
# "numbered_events should not differ from check")
#
#
# # Test that df has not been changed by the op
# self.assertTrue(list(df.columns) == list(df_test.columns),
# "split_rows should not change the input df columns")
Expand Down
1 change: 1 addition & 0 deletions tests/tools/remodeling/operations/test_number_rows_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def test_number_rows_new_column(self):
# Test when new column name is given with overwrite unspecified (=False)
parms = json.loads(self.json_parms)
op = NumberRowsOp(parms)
self.assertIsInstance(op, NumberRowsOp)
# df = pd.DataFrame(self.sample_data, columns=self.sample_columns)
# df_check = pd.DataFrame(self.numbered_data, columns=self.numbered_columns)
# df_test = pd.DataFrame(self.sample_data, columns=self.sample_columns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_do_ops(self):
"do_ops updating does not change number of categorical columns.")
context = dispatch.summary_dicts['test summary']
text_sum = context.get_text_summary()
self.assertIsInstance(text_sum, dict)
self.assertEqual(len(context.summary_dict), 2)

def test_get_summary(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_ambiguous_def_errors(self):
context = cont.get("get_definition_summary", None)
self.assertIsInstance(context, DefinitionSummary, "get_summary testing DefinitionSummary")
summary1a = context.get_summary()
self.assertIsInstance(summary1a, dict)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def test_quick3(self):
input_data = TabularInput(df, sidecar=my_sidecar, name="myName")
tag_man = HedTagManager(EventManager(input_data, my_schema), remove_types=remove_types)
counts = HedTagCounts('myName', 2)
summary_dict = {}
self.assertIsInstance(counts, HedTagCounts)
self.assertIsInstance(tag_man, HedTagManager)
# hed_objs = tag_man.get_hed_objs(include_context=include_context, replace_defs=replace_defs)
# for hed in hed_objs:
# counts.update_event_counts(hed, 'myName')
Expand Down Expand Up @@ -211,13 +212,13 @@ def test_get_summary_text_summary(self):
self.assertIn('Dataset', text_sum_none)
self.assertIsInstance(text_sum_none['Dataset'], str)
self.assertFalse(text_sum_none.get("Individual files", {}))

text_sum_consolidated = sum_context1.get_text_summary(individual_summaries="consolidated")
self.assertIn('Dataset', text_sum_consolidated)
self.assertIsInstance(text_sum_consolidated['Dataset'], str)
self.assertFalse(text_sum_consolidated.get("Individual files", {}))
self.assertGreater(len(text_sum_consolidated['Dataset']), len(text_sum_none['Dataset']))

text_sum_separate = sum_context1.get_text_summary(individual_summaries="separate")
self.assertIn('Dataset', text_sum_separate)
self.assertIsInstance(text_sum_separate['Dataset'], str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_summary(self):
self.assertEqual(len(summary2['Dataset']['Overall summary']['Files']), 2)
summary2a = context2.get_summary(individual_summaries="separate")
self.assertIsInstance(summary2a["Individual files"]["run-02"], dict)

def test_text_summary_with_levels(self):
with open(self.summary_path, 'r') as fp:
parms = json.load(fp)
Expand Down
Loading

0 comments on commit c519f1b

Please sign in to comment.