Browse Source

added failing test covering invalid root path '/'
when $SUBJECTS_DIR is set and arg `root_dir_path` is provided

Fabian Peter Hammerle 5 years ago
parent
commit
8fd97e7d69
4 changed files with 31 additions and 2 deletions
  1. 2 1
      Pipfile
  2. 9 1
      Pipfile.lock
  3. 1 0
      setup.py
  4. 19 0
      tests/hippocampus_test.py

+ 2 - 1
Pipfile

@@ -7,8 +7,9 @@ name = "pypi"
 freesurfer-volume-reader = {editable = true, path = "."}
 
 [dev-packages]
-pytest = "*"
 pylint = ">=2.3.0"
+pytest = "*"
+pytest-timeout = "*"
 
 [requires]
 python_version = "3"

+ 9 - 1
Pipfile.lock

@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "52976adb8c969665fe068d4030d9e1c2fc535bbe86cbfb5faaa4879164fc6f3c"
+            "sha256": "21ecadcfdbf53c5724b1c71278db767fe370cb29b6ad12846685fb4db30ed8de"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -203,6 +203,14 @@
             "index": "pypi",
             "version": "==4.4.1"
         },
+        "pytest-timeout": {
+            "hashes": [
+                "sha256:4a30ba76837a32c7b7cd5c84ee9933fde4b9022b0cd20ea7d4a577c2a1649fb1",
+                "sha256:d49f618c6448c14168773b6cdda022764c63ea80d42274e3156787e8088d04c6"
+            ],
+            "index": "pypi",
+            "version": "==1.3.3"
+        },
         "six": {
             "hashes": [
                 "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",

+ 1 - 0
setup.py

@@ -44,5 +44,6 @@ setuptools.setup(
     tests_require=[
         'pylint>=2.3.0',
         'pytest',
+        'pytest-timeout',
     ],
 )

+ 19 - 0
tests/hippocampus_test.py

@@ -152,6 +152,8 @@ def assert_volume_frames_equal(left: pandas.DataFrame, right: pandas.DataFrame):
      os.path.join(SUBJECTS_DIR, 'bert', 'hippocampal-volumes.csv')),
 ])
 def test_main_root_dir_param(capsys, root_dir_path, expected_csv_path):
+    if 'SUBJECTS_DIR' in os.environ:
+        del os.environ['SUBJECTS_DIR']
     with unittest.mock.patch('sys.argv', ['', root_dir_path]):
         freesurfer_volume_reader.main()
     out, _ = capsys.readouterr()
@@ -174,3 +176,20 @@ def test_main_root_dir_env(capsys, root_dir_path, expected_csv_path):
         left=pandas.read_csv(expected_csv_path),
         right=pandas.read_csv(io.StringIO(out)).drop(columns=['source_path']),
     )
+
+
+@pytest.mark.timeout(8)
+@pytest.mark.parametrize(('root_dir_path', 'subjects_dir', 'expected_csv_path'), [
+    (os.path.join(SUBJECTS_DIR, 'bert'),
+     os.path.join(SUBJECTS_DIR, 'alice'),
+     os.path.join(SUBJECTS_DIR, 'bert', 'hippocampal-volumes.csv')),
+])
+def test_main_root_dir_overwrite_env(capsys, root_dir_path, subjects_dir, expected_csv_path):
+    os.environ['SUBJECTS_DIR'] = subjects_dir
+    with unittest.mock.patch('sys.argv', ['', root_dir_path]):
+        freesurfer_volume_reader.main()
+    out, _ = capsys.readouterr()
+    assert_volume_frames_equal(
+        left=pandas.read_csv(expected_csv_path),
+        right=pandas.read_csv(io.StringIO(out)).drop(columns=['source_path']),
+    )