test_main.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import csv
  2. import io
  3. import subprocess
  4. import typing
  5. import unittest.mock
  6. from freesurfer_surface.__main__ import annotation_labels
  7. from conftest import ANNOTATION_FILE_PATH
  8. def check_rows(csv_rows: typing.List[str]):
  9. assert len(csv_rows) == 36 + 1
  10. assert csv_rows[0] == ['index', 'color', 'name']
  11. assert csv_rows[1] == ['0', '#190519', 'unknown']
  12. assert csv_rows[23] == ['22', '#dc1414', 'postcentral']
  13. assert csv_rows[25] == ['24', '#3c14dc', 'precentral']
  14. def test_annotation_labels_function(capsys):
  15. with unittest.mock.patch('sys.argv', ['', ANNOTATION_FILE_PATH]):
  16. annotation_labels()
  17. out, err = capsys.readouterr()
  18. assert not err
  19. check_rows(list(csv.reader(io.StringIO(out), delimiter='\t')))
  20. def test_annotation_labels_function_delimiter(capsys):
  21. with unittest.mock.patch('sys.argv', ['', '--delimiter', ',', ANNOTATION_FILE_PATH]):
  22. annotation_labels()
  23. out, err = capsys.readouterr()
  24. assert not err
  25. check_rows(list(csv.reader(io.StringIO(out), delimiter=',')))
  26. def test_annotation_labels_script():
  27. proc_info = subprocess.run(['freesurfer-annotation-labels', ANNOTATION_FILE_PATH],
  28. check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  29. assert not proc_info.stderr
  30. check_rows(list(csv.reader(io.StringIO(proc_info.stdout.decode()),
  31. delimiter='\t')))