def test_resolve_final_image_info(self, anchore_db):
     input_string = "anchore/test_images@sha256:2dceaabe73ee43341b0ab79aaa10f8d0c79b7866d9b4c31e1923a32e9cc4b586"
     session = get_thread_scoped_session()
     actual_image_info = catalog_impl.resolve_final_image_info(
         "admin", input_string, [], session, {})
     test_case = TestCase()
     test_case.maxDiff = None
     test_case.assertDictEqual(self.expected_full_image_info,
                               actual_image_info)
Esempio n. 2
0
def test_case():
    """
    Creates a new ``unittest.TestCase`` instance.

    Returns:
        unittest.TestCase
    """
    test = TestCase()
    test.maxDiff = None
    return test
 def compare(self, a, b):
     a = json.loads(a)
     b = json.loads(b)
     t = TestCase()
     t.maxDiff = None
     try:
         self.ttx += 1
         t.assertDictEqual(a, b)
     except AssertionError as e:
         self.ptx += 1
         print('[{} / {}] compared {} : FAILURE'.format(self.ptx, self.ttx, a['txid']))
Esempio n. 4
0
def test_config_and_options_match(translations):

    config = translations["config"]["step"]["choose_entities"]["data"]
    options = translations["options"]["step"]["user"]["data"]

    # remove expected differences
    config.pop("name", None)
    options.pop("host", None)
    options.pop("local_key", None)

    test = TestCase()
    test.maxDiff = None
    test.assertDictEqual(config, options)
Esempio n. 5
0
    def compare_properties(self, schema):
        """Compares two schemas. The schema used to call the method
        will be the one we compare from, in advance 'source schema'.
        The schema passed as parameter will be the 'target schema'.

        Returns -- dictionary {status, correct, missing, distinct, message}
            being:
                status 'OK' if all properties in source schema exist in target
                    schema with same values. 'KO' in other case.
                correct: list of properties that matches.
                missing: list of properties missing from target schema.
                distinct: list of properties in both schemas but having
                    with different values.
                message: a string with additional information.
        """
        test_case = TestCase('__init__')
        test_case.maxDiff = None

        status = 'OK'
        correct = []
        missing = []
        distinct = []
        msg = ''
        for pname, pvalue in self.get_properties().items():
            if pname not in schema.get_properties():
                missing.append(pname)
                msg = msg + '\n' + '* Missing property: ' + pname
                status = 'KO'
            else:
                try:
                    test_case.assertDictEqual(pvalue,
                                              schema.get_properties()[pname])
                    correct.append(pname)

                except AssertionError as e:
                    distinct.append(pname)
                    msg = "%s\n* Type mismatch: \n\t%s: %s" %\
                        (msg, pname, str(e).replace('\n', '\n\t'))
                    status = 'KO'

        return {
            'status': status,
            'correct': correct,
            'missing': missing,
            'distinct': distinct,
            'msg': msg
        }
Esempio n. 6
0
    def compare_properties(self, schema):
        """Compares two schemas. The schema used to call the method
        will be the one we compare from, in advance 'source schema'.
        The schema passed as parameter will be the 'target schema'.

        Returns -- dictionary {status, correct, missing, distinct, message}
            being:
                status 'OK' if all properties in source schema exist in target
                    schema with same values. 'KO' in other case.
                correct: list of properties that matches.
                missing: list of properties missing from target schema.
                distinct: list of properties in both schemas but having
                    with different values.
                message: a string with additional information.
        """
        test_case = TestCase('__init__')
        test_case.maxDiff = None

        status = 'OK'
        correct = []
        missing = []
        distinct = []
        msg = ''
        for pname, pvalue in self.get_properties().items():
            if pname not in schema.get_properties():
                missing.append(pname)
                msg = msg + '\n' + '* Missing property: ' + pname
                status = 'KO'
            else:
                try:
                    test_case.assertDictEqual(pvalue,
                                              schema.get_properties()[pname])
                    correct.append(pname)

                except AssertionError as e:
                    distinct.append(pname)
                    msg = "%s\n* Type mismatch: \n\t%s: %s" %\
                        (msg, pname, str(e).replace('\n', '\n\t'))
                    status = 'KO'

        return {'status': status, 'correct': correct, 'missing': missing,
                'distinct': distinct, 'msg': msg}
Esempio n. 7
0
def test_images(tmp_path: Path):
    statmap_path = tmp_path / "statmap.nii.gz"
    statmap_path.touch()

    result: ResultDict = {
        "tags": {
            "task": "faces",
            "feature": "taskBased1",
            "taskcontrast": "facesGtScrambled",
            "run": "07",
            "sub": "01",
        },
        "images": {
            "variance": statmap_path,
            "effect": statmap_path,
            "mask": statmap_path,
            "dof": statmap_path,
            "z": statmap_path,
        },
        "vals": {
            "dummy_scans": 0,
        },
        "metadata": {
            "acquisition_orientation": "LAS",
        },
    }

    save_images([result], tmp_path)

    index = BIDSIndex()
    index.put(tmp_path / "derivatives" / "halfpipe")

    (actual,) = load_images(index)

    test_case = TestCase()
    test_case.maxDiff = None

    test_case.assertDictEqual(result["tags"], actual["tags"])
    test_case.assertDictEqual(result["vals"], actual["vals"])
    test_case.assertDictEqual(result["metadata"], actual["metadata"])
    assert result["images"].keys() == actual["images"].keys()
def test_test_draw(tmpdir, model, rescale):
    """Verify that the `test_draw` method works.

    This method checks that samples can be drawn from the flow and then
    resets the flows. This test makes sure the flow is correctly reset.
    """
    output = tmpdir.mkdir('test')
    fp = FlowProposal(model,
                      output=output,
                      poolsize=100,
                      rescale_parameters=rescale)
    fp.initialise()
    # Call these since they are worked out the first time they're called
    fp.x_dtype, fp.x_prime_dtype
    orig_state = fp.__getstate__()

    t = TestCase()
    t.maxDiff = None
    t.assertDictEqual(fp.__getstate__(), orig_state)
    fp.test_draw()
    t.assertDictEqual(fp.__getstate__(), orig_state)
from behave import use_step_matcher, step
from unittest import TestCase
import subprocess
import re

test_case = TestCase()
test_case.maxDiff = None
assertEqual = test_case.assertEqual
assertFalse = test_case.assertFalse

VERSION_MATCHER = re.compile('^Python ((\d+\.\d+)\.\d+)')

use_step_matcher("re")


@step("I run the docker container for '(.*)'")
def run_docker_container(context, container_name: str) -> None:
    context.container_name = container_name


@step("I get as output '(.*)'")
def check_expected_output(context, expected):
    assertEqual(expected, context.docker_output)


@step("I get as version '(.*)'")
def check_expected_version(context, version):
    for line in context.docker_output.split('\n'):  # type: str
        if re.match('\w+ version "%s_\d+"' % re.escape(version), line):
            return
Esempio n. 10
0
        
        for i in range(len(nums)):
            n = nums.pop(0)
            perms = self.permute(nums)
            
            for perm in perms:
                perm.append(n)
            result.extend(perms)
            nums.append(n)
            
        return result
    
if __name__ == "__main__":
    
    t = TestCase()
    t.maxDiff = None
    s = Solution()
    t.assertCountEqual([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],
                       s.permute([1, 2, 3]))

    t.assertCountEqual([[0,1],[1,0]], s.permute([0, 1]))
    
    # 4! = 24
    t.assertCountEqual([[3, 2, 1, 0], [2, 3, 1, 0], [1, 3, 2, 0], [3, 1, 2, 0],
                        [2, 1, 3, 0], [1, 2, 3, 0], [0, 3, 2, 1], [3, 0, 2, 1],
                        [2, 0, 3, 1], [0, 2, 3, 1], [3, 2, 0, 1], [2, 3, 0, 1],
                        [1, 0, 3, 2], [0, 1, 3, 2], [3, 1, 0, 2], [1, 3, 0, 2],
                        [0, 3, 1, 2], [3, 0, 1, 2], [2, 1, 0, 3], [1, 2, 0, 3],
                        [0, 2, 1, 3], [2, 0, 1, 3], [1, 0, 2, 3], [0, 1, 2, 3]],
                       s.permute([0, 1, 2, 3]))
    print('OK!')
Esempio n. 11
0
def test_xml2dict(xml, to_lower, expected):
    tc = TestCase()
    tc.maxDiff = None
    tc.assertDictEqual(functions.xml2dict(xml, to_lower=to_lower), expected)