Esempio n. 1
0
    def test_no_outputs_checkOutputIndices_good(self):
        """Test output index check, one well-indexed output case."""
        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())

        foo.check_output_indices()
        foo.clean()
Esempio n. 2
0
    def test_one_valid_output_checkOutputIndices_good(self):
        """Test output index check, one well-indexed output case."""

        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())
        out = foo.outputs.create(dataset_idx=1)
        out.transformationoutput = out

        foo.check_output_indices()
        foo.clean()
Esempio n. 3
0
    def test_many_valid_outputs_scrambled_checkOutputIndices_good(self):
        """Test output index check, well-indexed multi-output (scrambled order) case."""

        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())
        for i in (3, 1, 2):
            out = foo.outputs.create(dataset_idx=i)
            out.transformationoutput = out

        foo.check_output_indices()
        foo.clean()
Esempio n. 4
0
    def test_no_inputs_checkInputIndices_good(self):
        """
        Method with no inputs defined should have
        check_input_indices() return with no exception.
        """

        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())

        # check_input_indices() should not raise a ValidationError
        foo.check_input_indices()
        foo.clean()
Esempio n. 5
0
    def test_single_valid_input_checkInputIndices_good(self):
        """
        Method with a single, 1-indexed input should have
        check_input_indices() return with no exception.
        """

        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())
        inp = foo.inputs.create(dataset_idx=1)
        inp.transformationinput = inp

        # check_input_indices() should not raise a ValidationError
        foo.check_input_indices()
        foo.clean()
Esempio n. 6
0
    def test_many_ordered_valid_inputs_checkInputIndices_good(self):
        """
        Test check_input_indices on a method with several inputs,
        correctly indexed and in order.
        """

        driver = CodeResourceRevision(coderesource=CodeResource())

        foo = Method(driver=driver, family=MethodFamily())
        for i in range(3):
            inp = foo.inputs.create(dataset_idx=i + 1)
            inp.transformationinput = inp

        # check_input_indices() should not raise a ValidationError
        foo.check_input_indices()
        foo.clean()
Esempio n. 7
0
class MethodDependencyMockTests(TestCase):
    def setUp(self):
        patcher = mocked_relations(Method, MethodDependency, Transformation)
        patcher.start()
        self.addCleanup(patcher.stop)
        driver = CodeResourceRevision(
            coderesource=CodeResource(filename='driver.py'))
        self.method = Method(driver=driver, family=MethodFamily())
        self.dependency = self.add_dependency('helper.py')

    def add_dependency(self, filename):
        helper = CodeResourceRevision(
            coderesource=CodeResource(filename=filename))
        dependency = self.method.dependencies.create(requirement=helper)
        dependency.method = self.method
        return dependency

    def test_dependency_depends_on_nothing_clean_good(self):
        self.method.dependencies.clear()

        self.method.clean()

    def test_dependency_current_folder_same_name_clean_bad(self):
        """
        A depends on B - current folder, same name
        """
        # We're giving the dependency a conflicting filename.
        self.dependency.filename = self.method.driver.coderesource.filename

        self.assertRaisesRegexp(ValidationError,
                                "Conflicting dependencies",
                                self.method.clean)

    def test_dependency_current_folder_different_name_clean_good(self):
        """
        1 depends on 2 - current folder, different name
        """
        self.dependency.filename = 'different_name.py'

        self.method.clean()

    def test_dependency_inner_folder_same_name_clean_good(self):
        """
        1 depends on 2 - different folder, same name
        """
        self.dependency.path = 'subfolder'
        self.dependency.filename = self.method.driver.coderesource.filename

        self.method.clean()

    def test_dependency_inner_folder_different_name_clean_good(self):
        """
        1 depends on 2 - different folder, different name
        """
        self.dependency.path = 'subfolder'
        self.dependency.filename = 'different_name.py'

        self.method.clean()

    def test_dependency_A_depends_BC_same_folder_no_conflicts_clean_good(self):
        """
        A depends on B, A depends on C
        BC in same folder as A
        Nothing conflicts
        """
        self.add_dependency('helper2.py')

        self.method.clean()

    def test_dependency_A_depends_BC_same_folder_B_conflicts_with_C_clean_bad(self):
        """
        A depends on B, A depends on C
        BC in same folder as A, BC conflict
        """
        self.dependency.filename = 'same_name.py'
        self.add_dependency(self.dependency.filename)

        self.assertRaisesRegexp(
            ValidationError,
            "Conflicting dependencies",
            self.method.clean)

    def test_list_all_filepaths_unnested_dep_blank_filename(self):
        """
        List all filepaths when dependency has no filename set and is not in a subdirectory.
        """
        expected_filepaths = ['driver.py', 'helper.py']

        filepaths = self.method.list_all_filepaths()

        self.assertEqual(expected_filepaths, filepaths)

    def test_list_all_filepaths_nested_dep_blank_filename(self):
        """
        List all filepaths when dependency has no filename set and is in a subdirectory.
        """
        self.dependency.path = 'nest_folder'
        expected_filepaths = ['driver.py', 'nest_folder/helper.py']

        filepaths = self.method.list_all_filepaths()

        self.assertEqual(expected_filepaths, filepaths)

    def test_list_all_filepaths_unnested_dep_specified_filename(self):
        """List all filepaths when dependency has a custom filename and is not in a subdirectory.
        """
        self.dependency.filename = 'foo.py'
        expected_filepaths = ['driver.py', 'foo.py']

        filepaths = self.method.list_all_filepaths()

        self.assertEqual(expected_filepaths, filepaths)

    def test_list_all_filepaths_nested_dep_specified_filename(self):
        """
        List all filepaths when dependency has a custom filename and is in a subdirectory.
        """
        self.dependency.path = 'nest_folder'
        self.dependency.filename = 'foo.py'
        expected_filepaths = ['driver.py', 'nest_folder/foo.py']

        filepaths = self.method.list_all_filepaths()

        self.assertEqual(expected_filepaths, filepaths)