<commit_before>#!/usr/bin/env python
"""
Test of NIDM FSL export tool


@author: <NAME> <<EMAIL>>
@copyright: University of Warwick 2013-2014
"""
import os
import shutil
import sys
import glob
import json
import copy
import zipfile
import git
import subprocess

import logging
logger = logging.getLogger(__name__)
# Display log messages in console
logging.basicConfig(filename='debug.log', level=logging.DEBUG, filemode='w',
                    format='%(levelname)s - %(message)s')

RELPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Add FSL NIDM export to python path
sys.path.append(RELPATH)

# Add nidm common testing code folder to python path
NIDM_DIR = os.path.join(RELPATH, "nidm")
# In TravisCI the nidm repository will be created as a subtree, however locally
# the nidm directory will be accessed directly
logging.debug(NIDM_DIR)
if not os.path.isdir(NIDM_DIR):
    NIDM_DIR = os.path.join(os.path.dirname(RELPATH), "nidm")

# The FSL export to NIDM will only be run locally (for now)
from nidmfsl.fsl_exporter.fsl_exporter import FSLtoNIDMExporter

NIDM_RESULTS_DIR = os.path.join(NIDM_DIR, "nidm", "nidm-results")
TERM_RESULTS_DIRNAME = "terms"
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DATA_DIR = os.path.join(TEST_DIR, "data")

path = os.path.join(NIDM_RESULTS_DIR, "test")
sys.path.append(path)


from TestCommons import *
from CheckConsistency import *


if __name__ == '__main__':
    config_file = os.path.join(TEST_DIR, 'config.json')
    if os.path.isfile(config_file):
        # Read config json file to find nidmresults-examples repository
        with open(config_file) as data_file:
            metadata = json.load(data_file)
        test_data_dir = metadata["data"]
    else:
        # Pull nidmresults-examples repository
        test_data_dir = os.path.join(TEST_DATA_DIR, "nidmresults-examples")

    if not os.path.isdir(os.path.join(test_data_dir, ".git")):
        logging.debug("Cloning to " + test_data_dir)
        # Cloning test data repository
        data_repo = git.Repo.clone_from(
            "https://github.com/incf-nidash/nidmresults-examples.git",
            test_data_dir)
    else:
        # Updating test data repository
        logging.debug("Updating repository at " + test_data_dir)
        data_repo = git.Repo(test_data_dir)
        origin = data_repo.remote("origin")
        subprocess.call(
            ["cd " + test_data_dir + "; git checkout master"],
            shell=True)
        subprocess.call(
            ["cd " + test_data_dir + "; git fetch origin"],
            shell=True)
        subprocess.call(
            ["cd " + test_data_dir + "; git checkout origin/add_onset_files_for_fsl_full"],
            shell=True)
        # "git stash" gives the repo one more chance to checkout the files
        # if something failed (e.g. git lfs error) during pull
        subprocess.call(
            ["cd " + test_data_dir + "; git stash"],
            shell=True)<commit_msg>Use main master branch (and cmd rather than gitpython)<commit_after>#!/usr/bin/env python
"""
Test of NIDM FSL export tool


@author: <NAME> <<EMAIL>>
@copyright: University of Warwick 2013-2014
"""
import os
import shutil
import sys
import glob
import json
import copy
import zipfile
import git
import subprocess

import logging
logger = logging.getLogger(__name__)
# Display log messages in console
logging.basicConfig(filename='debug.log', level=logging.DEBUG, filemode='w',
                    format='%(levelname)s - %(message)s')

RELPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Add FSL NIDM export to python path
sys.path.append(RELPATH)

# Add nidm common testing code folder to python path
NIDM_DIR = os.path.join(RELPATH, "nidm")
# In TravisCI the nidm repository will be created as a subtree, however locally
# the nidm directory will be accessed directly
logging.debug(NIDM_DIR)
if not os.path.isdir(NIDM_DIR):
    NIDM_DIR = os.path.join(os.path.dirname(RELPATH), "nidm")

# The FSL export to NIDM will only be run locally (for now)
from nidmfsl.fsl_exporter.fsl_exporter import FSLtoNIDMExporter

NIDM_RESULTS_DIR = os.path.join(NIDM_DIR, "nidm", "nidm-results")
TERM_RESULTS_DIRNAME = "terms"
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DATA_DIR = os.path.join(TEST_DIR, "data")

path = os.path.join(NIDM_RESULTS_DIR, "test")
sys.path.append(path)


from TestCommons import *
from CheckConsistency import *


if __name__ == '__main__':
    config_file = os.path.join(TEST_DIR, 'config.json')
    if os.path.isfile(config_file):
        # Read config json file to find nidmresults-examples repository
        with open(config_file) as data_file:
            metadata = json.load(data_file)
        test_data_dir = metadata["data"]
    else:
        # Pull nidmresults-examples repository
        test_data_dir = os.path.join(TEST_DATA_DIR, "nidmresults-examples")

    if not os.path.isdir(os.path.join(test_data_dir, ".git")):
        logging.debug("Cloning to " + test_data_dir)
        # Cloning test data repository
        data_repo = git.Repo.clone_from(
            "https://github.com/incf-nidash/nidmresults-examples.git",
            test_data_dir)
    else:
        # Updating test data repository
        logging.debug("Updating repository at " + test_data_dir)
        subprocess.call(
            ["cd " + test_data_dir + "; git checkout master"],
            shell=True)
        subprocess.call(
            ["cd " + test_data_dir + "; git pull origin master"],
            shell=True)
        # "git stash" gives the repo one more chance to checkout the files
        # if something failed (e.g. git lfs error)
        subprocess.call(
            ["cd " + test_data_dir + "; git stash"],
            shell=True)
{'fraction_non_alphanumeric': 0.10750260507120528, 'fraction_numerical': 0.0027787426189649182, 'mean_word_length': 3.2627683197631385, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7362709', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1880, 'n_words': 477}