"""Test BIDSValidator functionality.

git-annex and datalad are used to download a test data structure without the
actual file contents.

"""
import os
import datalad.api

from bids_validator import BIDSValidator


def test_is_bids():
    """Test that is_bids returns true for each file in a valid BIDS dataset."""
    # Download testing data as git annex dataset
    HOME = os.path.expanduser('~')
    dspath = os.path.join(HOME, 'eeg_matchingpennies_git_annex')
    url = 'https://github.com/sappelhoff/eeg_matchingpennies'
    datalad.api.install(dspath, url)

    def _exclude_this(fname):
        """Help to skip certain files from being validated."""
        exclude_keywords = ['git', 'datalad', 'sourcedata', 'bidsignore']
        for keyword in exclude_keywords:
            if keyword in fname:
                return True

        return False

    # Gather all files
    files = []
    for r, _, f in os.walk(dspath):
        for file in f:
            fname = os.path.join(r, file)
            if not _exclude_this(fname):
                files.append(fname)

    # Test all files
    validator = BIDSValidator()
    false_decisions = []
    for file in files:
        if not validator.is_bids(file):
            false_decisions.append(file)

    if len(false_decisions) > 0:
        raise AssertionError('False decisions for the following files: {}'
                             .format(false_decisions))

    # Sanity check: Does it raise for wrong files?
    assert not validator.is_bids('bogus')

@@ -144,16 +144,31 @@
 mport os
+%0A%0Aimport pytest
 %0Aimport 
@@ -226,381 +226,266 @@
 or%0A%0A
-%0Adef test_is_bids():%0A    %22%22%22Test that is_bids returns true for each file in a valid BIDS dataset.%22%22%22%0A    # Download testing data as git annex dataset%0A    HOME = os.path.expanduser('~')%0A    dspath = os.path.join(HOME, 'eeg_matchingpennies_git_annex')%0A    url = 'https://github.com/sappelhoff/eeg_matchingpennies'%0A    datalad.api.install(dspath, url)%0A%0A    def _exclude_this(f
+HOME = os.path.expanduser('~')%0A%0ATEST_DATA_DICT = %7B%0A    'eeg_matchingpennies': 'https://github.com/sappelhoff/eeg_matchingpennies'%0A    %7D%0A%0AEXCLUDE_KEYWORDS = %5B'git', 'datalad', 'sourcedata', 'bidsignore', 'LICENSE'%5D%0A%0A%0Adef _download_test_data(test_data_dict, ds
 name
@@ -495,61 +495,42 @@
     
- 
-   %22%22%22Help to skip certain files from being validate
+%22%22%22Download test data using datala
 d.%22%22
@@ -539,100 +539,164 @@
     
- 
-   exclude_keywords = %5B'git', 'datalad', 'sourcedata', 'bidsignore'%5D%0A        for keyword in
+url = test_data_dict%5Bdsname%5D%0A    dspath = os.path.join(HOME, dsname)%0A    datalad.api.install(dspath, url)%0A    return dspath%0A%0A%0Adef _gather_test_files(dspath,
  exc
@@ -712,116 +712,75 @@
 ords
+)
 :%0A    
-        if keyword in fname:%0A                return True%0A%0A        return False%0A%0A    # Gather all files
+%22%22%22Get test files from dataset path, relative to dataset.%22%22%22
 %0A   
@@ -908,471 +908,472 @@
     
-if not _exclude_this(fname):%0A                files.append(fname)%0A%0A    # Test all files%0A    validator = BIDSValidator()%0A    false_decisions = %5B%5D%0A    for file in files:%0A        if not validator.is_bids(file):%0A            false_decisions.append(
+fname = fname.replace(dspath, '')%0A            if not any(keyword in fname for keyword in exclude_keywords):%0A                files.append(fname)%0A%0A    return files%0A%0A%0Adspath = _download_test_data(TEST_DATA_DICT, 'eeg_matchingpennies')%0Afiles = _gather_test_files(dspath, EXCLUDE_KEYWORDS)%0A%0A%0A@pytest.mark.parametrize('fname', 
 file
+s
 )%0A
-%0A    if len(false_decisions) %3E 0:%0A        raise AssertionError('False decisions for the following files: %7B%7D'%0A                             .format(false_decisions))%0A%0A    # Sanity check: Does it raise for wrong files?
+def test_is_bids(fname):%0A    %22%22%22Test that is_bids returns true for each file in a valid BIDS dataset.%22%22%22%0A    validator = BIDSValidator()
 %0A   
@@ -1380,20 +1380,16 @@
  assert 
-not 
 validato
@@ -1402,13 +1402,11 @@
 ids(
-'bogus'
+fname
 )%0A

fix python tests