<commit_before>from unittest import TestCase

import copy

import StringIO
import yaml

from dax import processor_parser


class TestResource:

    def __init__(self, label, file_count):
        self.label_ = label
        self.file_count_ = file_count

    def label(self):
        return self.label_

    def file_count(self):
        return self.file_count_


class TestArtefact:

    def __init__(self, id, artefact_type, quality, resources):
        self.id_ = id
        self.artefact_type = artefact_type
        self.quality_ = quality
        self.resources = [TestResource(r[0], r[1]) for r in resources]

    def id(self):
        return self.id_

    def type(self):
        return self.artefact_type

    def quality(self):
        return self.quality_

    def usable(self):
        return self.quality() == 'usable'

    def unusable(self):
        return self.quality() == 'unusable'

    def get_resources(self):
        return self.resources


class TestSession:

    def __init__(self, scans, asrs):
        self.scans_ = [TestArtefact(s[0], s[1], s[2], s[3]) for s in scans]
        self.assessors_ = [TestArtefact(a[0], a[1], a[2], a[3]) for a in asrs]

    def scans(self):
        return self.scans_

    def assessors(self):
        return self.assessors_


proj = 'proj1'
subj = 'subj1'
sess = 'sess1'

scan_files = [('SNAPSHOTS', 2), ('NIFTI', 1)]

xnat_scan_contents = [
    ("1", "T1W", "usable", copy.deepcopy(scan_files)),
    ("2", "T1w", "unusable", copy.deepcopy(scan_files)),
    ("3", "T1", "usable", copy.deepcopy(scan_files)),
    ("4", "T1", "usable", copy.deepcopy(scan_files)),
    ("10", "FLAIR", "usable", copy.deepcopy(scan_files)),
    ("11", "FLAIR", "usable", copy.deepcopy(scan_files)),
]


asr_prefix = '-x-'.join((proj, subj, sess, ''))

asr_files = [
    ('LABELS', 1), ('PDF', 1), ('BIAS_COR', 1), ('PRIOR', 1), ('SEG', 1),
    ('STATS', 1), ('SNAPSHOTS', 2), ('OUTLOG', 1), ('PBS', 1)
]

xnat_assessor_contents = [
    (asr_prefix + "proc1-asr1", "proc1", "usable", copy.deepcopy(asr_files)),
    #(asr_prefix + "proc1-asr2", "proc1", "usable", copy.deepcopy(asr_files))
]

scan_path = 'xnat:/project/{}/subject/{}/experiment/{}/scan/{}/resource/{}'
assessor_path =\
    'xnat:/project/{}/subject/{}/experiment/{}/assessor/{}/resource/{}'

xnat_assessor_inputs = {
    'proc2-asr1': {
        't1': scan_path.format(proj, subj, sess, '1', 'NIFTI'),
        'fl': scan_path.format(proj, subj, sess, '11', 'NIFTI'),
        'seg': assessor_path.format(proj, subj, sess, 'proc1-asr1', 'SEG')
    }
}


scan_gif_parcellation_yaml = """
---
inputs:<commit_msg>Fixed broken processor_parser unit test<commit_after>from unittest import TestCase

import copy

import StringIO
import yaml

from dax import processor_parser


class TestResource:

    def __init__(self, label, file_count):
        self.label_ = label
        self.file_count_ = file_count

    def label(self):
        return self.label_

    def file_count(self):
        return self.file_count_


class TestArtefact:

    def __init__(self, id, artefact_type, quality, resources, inputs):
        self.id_ = id
        self.artefact_type = artefact_type
        self.quality_ = quality
        self.resources = [TestResource(r[0], r[1]) for r in resources]
        self.inputs = inputs

    def id(self):
        return self.id_

    def type(self):
        return self.artefact_type

    def quality(self):
        return self.quality_

    def usable(self):
        return self.quality() == 'usable'

    def unusable(self):
        return self.quality() == 'unusable'

    def get_resources(self):
        return self.resources

    def get_inputs(self):
        return self.inputs


class TestSession:

    def __init__(self, scans, asrs):
        self.scans_ = [TestArtefact(s[0], s[1], s[2], s[3], {}) for s in scans]
        self.assessors_ = [TestArtefact(a[0], a[1], a[2], a[3], a[4]) for a in asrs]

    def scans(self):
        return self.scans_

    def assessors(self):
        return self.assessors_


proj = 'proj1'
subj = 'subj1'
sess = 'sess1'

scan_files = [('SNAPSHOTS', 2), ('NIFTI', 1)]

xnat_scan_contents = [
    ("1", "T1W", "usable", copy.deepcopy(scan_files)),
    ("2", "T1w", "unusable", copy.deepcopy(scan_files)),
    ("3", "T1", "usable", copy.deepcopy(scan_files)),
    ("4", "T1", "usable", copy.deepcopy(scan_files)),
    ("10", "FLAIR", "usable", copy.deepcopy(scan_files)),
    ("11", "FLAIR", "usable", copy.deepcopy(scan_files)),
]


asr_prefix = '-x-'.join((proj, subj, sess, ''))

asr_files = [
    ('LABELS', 1), ('PDF', 1), ('BIAS_COR', 1), ('PRIOR', 1), ('SEG', 1),
    ('STATS', 1), ('SNAPSHOTS', 2), ('OUTLOG', 1), ('PBS', 1)
]

scan_path = 'xnat:/project/{}/subject/{}/experiment/{}/scan/{}/resource/{}'
assessor_path =\
    'xnat:/project/{}/subject/{}/experiment/{}/assessor/{}/resource/{}'

xnat_assessor_inputs = {
    'proc1-asr1': {
        't1': scan_path.format(proj, subj, sess, '1', 'NIFTI')
    },
    'proc1-asr2': {
        't1': scan_path.format(proj, subj, sess, '1', 'NIFTI')
    },
    'proc2-asr1': {
        't1': scan_path.format(proj, subj, sess, '1', 'NIFTI'),
        'fl': scan_path.format(proj, subj, sess, '11', 'NIFTI'),
        'seg': assessor_path.format(proj, subj, sess, 'proc1-asr1', 'SEG')
    }
}

xnat_assessor_contents = [
    ("proc1-asr1", "proc1", "usable", copy.deepcopy(asr_files), xnat_assessor_inputs['proc1-asr1']),
    ("proc1-asr2", "proc1", "usable", copy.deepcopy(asr_files), xnat_assessor_inputs['proc1-asr2'])
]



scan_gif_parcellation_yaml = """
---
inputs:
{'fraction_non_alphanumeric': 0.17855218250404167, 'fraction_numerical': 0.020298185737380996, 'mean_word_length': 3.2471395881006866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3385341', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2066, 'n_words': 439}