Пример #1
0
 def setUp(self, OSUtilMock):
     self.osutils = OSUtilMock.return_value
     self.osutils.pipe = "PIPE"
     self.popen = FakePopen()
     self.osutils.popen.side_effect = [self.popen]
     self.binaries = {"go": BinaryPath(resolver=Mock(), validator=Mock(), binary="go", binary_path="/path/to/go")}
     self.under_test = GoModulesBuilder(self.osutils, self.binaries)
Пример #2
0
    def test_must_fail_workflow_binary_validation_failure(self):
        action_mock = Mock()
        validator_mock = Mock()
        validator_mock.validate = Mock()
        validator_mock.validate = MagicMock(
            side_effect=MisMatchRuntimeError(language="test",
                                             required_runtime="test1",
                                             runtime_path="/usr/bin/binary"))
        resolver_mock = Mock()
        resolver_mock.exec_paths = ["/usr/bin/binary"]
        binaries_mock = Mock()
        binaries_mock.return_value = []

        self.work.get_validators = lambda: validator_mock
        self.work.get_resolvers = lambda: resolver_mock
        self.work.actions = [
            action_mock.action1, action_mock.action2, action_mock.action3
        ]
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=resolver_mock,
                       validator=validator_mock,
                       binary="binary")
        }
        with self.assertRaises(WorkflowFailedError) as ex:
            self.work.run()
Пример #3
0
    def test_must_execute_actions_in_sequence(self):
        action_mock = Mock()
        validator_mock = Mock()
        validator_mock.validate = Mock()
        validator_mock.validate.return_value = '/usr/bin/binary'
        resolver_mock = Mock()
        resolver_mock.exec_paths = ['/usr/bin/binary']
        binaries_mock = Mock()
        binaries_mock.return_value = []

        self.work.get_validators = lambda: validator_mock
        self.work.get_resolvers = lambda: resolver_mock
        self.work.actions = [
            action_mock.action1, action_mock.action2, action_mock.action3
        ]
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=resolver_mock,
                       validator=validator_mock,
                       binary="binary")
        }
        self.work.run()

        self.assertEquals(action_mock.method_calls, [
            call.action1.execute(),
            call.action2.execute(),
            call.action3.execute()
        ])
        self.assertTrue(validator_mock.validate.call_count, 1)
Пример #4
0
    def test_action_must_call_builder_with_architecture(
            self, DependencyBuilderMock, PythonPipDependencyBuilderMock):
        builder_instance = PythonPipDependencyBuilderMock.return_value

        action = PythonPipBuildAction(
            "artifacts",
            "scratch_dir",
            "manifest",
            "runtime",
            None,
            {
                "python":
                BinaryPath(resolver=Mock(),
                           validator=Mock(),
                           binary="python",
                           binary_path=sys.executable)
            },
            ARM64,
        )
        action.execute()

        DependencyBuilderMock.assert_called_with(osutils=ANY,
                                                 pip_runner=ANY,
                                                 runtime="runtime",
                                                 architecture=ARM64)

        builder_instance.build_dependencies.assert_called_with(
            artifacts_dir_path="artifacts",
            scratch_dir_path="scratch_dir",
            requirements_path="manifest")
 def binaries(self):
     if not self._binaries:
         resolvers = self.get_resolvers()
         validators = self.get_validators()
         self._binaries = {resolver.binary: BinaryPath(resolver=resolver, validator=validator, binary=resolver.binary)
                          for resolver, validator in zip(resolvers, validators)}
     return self._binaries
Пример #6
0
    def test_must_raise_for_unknown_runtime(self):
        action_mock = Mock()
        validator_mock = Mock()
        validator_mock.validate = Mock()
        validator_mock.validate = MagicMock(
            side_effect=UnsupportedRuntimeError(runtime="runtime"))

        resolver_mock = Mock()
        resolver_mock.exec_paths = ["/usr/bin/binary"]
        binaries_mock = Mock()
        binaries_mock.return_value = []

        self.work.get_validators = lambda: validator_mock
        self.work.get_resolvers = lambda: resolver_mock
        self.work.actions = [
            action_mock.action1, action_mock.action2, action_mock.action3
        ]
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=resolver_mock,
                       validator=validator_mock,
                       binary="binary")
        }
        with self.assertRaises(WorkflowFailedError) as ex:
            self.work.run()

        self.assertIn("Runtime runtime is not supported", str(ex.exception))
Пример #7
0
 def setUp(self, MockOSUtils):
     self.os_utils = MockOSUtils.return_value
     self.os_utils.exists.side_effect = lambda d: True
     self.popen = FakePopen()
     self.os_utils.popen.side_effect = [self.popen]
     self.maven_path = '/path/to/mvn'
     self.maven_binary = BinaryPath(None, None, 'mvn', binary_path=self.maven_path)
     self.source_dir = '/foo/bar/helloworld'
     self.module_name = 'helloworld'
Пример #8
0
 def setUp(self, MockOSUtils):
     self.os_utils = MockOSUtils.return_value
     self.os_utils.exists.side_effect = lambda d: True
     self.popen = FakePopen()
     self.os_utils.popen.side_effect = [self.popen]
     self.gradle_path = "/path/to/gradle"
     self.gradle_binary = BinaryPath(None, None, "gradle", binary_path=self.gradle_path)
     self.source_dir = "/foo/bar/baz"
     self.manifest_path = "/foo/bar/baz/build.gradle"
     self.init_script = "/path/to/init"
Пример #9
0
    def test_action_must_call_builder(self, PythonPipDependencyBuilderMock):
        builder_instance = PythonPipDependencyBuilderMock.return_value

        action = PythonPipBuildAction(
            "artifacts", "scratch_dir", "manifest", "runtime", {
                "python":
                BinaryPath(resolver=Mock(),
                           validator=Mock(),
                           binary="python",
                           binary_path=sys.executable)
            })
        action.execute()

        builder_instance.build_dependencies.assert_called_with(
            "artifacts", "scratch_dir", "manifest")
Пример #10
0
    def test_must_raise_exception_on_failure(self,
                                             PythonPipDependencyBuilderMock):
        builder_instance = PythonPipDependencyBuilderMock.return_value
        builder_instance.build_dependencies.side_effect = PackagerError()

        action = PythonPipBuildAction(
            "artifacts", "scratch_dir", "manifest", "runtime", {
                "python":
                BinaryPath(resolver=Mock(),
                           validator=Mock(),
                           binary="python",
                           binary_path=sys.executable)
            })

        with self.assertRaises(ActionFailedError):
            action.execute()
Пример #11
0
    def mock_binaries(self):
        self.validator_mock = Mock()
        self.validator_mock.validate = Mock()
        self.validator_mock.validate.return_value = "/usr/bin/binary"
        self.resolver_mock = Mock()
        self.resolver_mock.exec_paths = ["/usr/bin/binary"]
        self.binaries_mock = Mock()
        self.binaries_mock.return_value = []

        self.work.get_validators = lambda: self.validator_mock
        self.work.get_resolvers = lambda: self.resolver_mock
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=self.resolver_mock,
                       validator=self.validator_mock,
                       binary="binary")
        }
Пример #12
0
    def test_must_raise_for_incompatible_runtime_and_architecture(self):
        self.work = self.MyWorkflow(
            "source_dir",
            "artifacts_dir",
            "scratch_dir",
            "manifest_path",
            runtime="python3.7",
            executable_search_paths=[str(pathlib.Path(os.getcwd()).parent)],
            optimizations={"a": "b"},
            options={"c": "d"},
        )
        action_mock = Mock()
        validator_mock = Mock()
        validator_mock.validate = Mock()
        validator_mock.validate = MagicMock(
            side_effect=UnsupportedArchitectureError(runtime="python3.7",
                                                     architecture="arm64"))

        resolver_mock = Mock()
        resolver_mock.exec_paths = ["/usr/bin/binary"]
        binaries_mock = Mock()
        binaries_mock.return_value = []

        self.work.architecture = "arm64"
        self.work.get_validators = lambda: validator_mock
        self.work.get_resolvers = lambda: resolver_mock
        self.work.actions = [
            action_mock.action1, action_mock.action2, action_mock.action3
        ]
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=resolver_mock,
                       validator=validator_mock,
                       binary="binary")
        }
        with self.assertRaises(WorkflowFailedError) as ex:
            self.work.run()

        self.assertIn(
            "Architecture arm64 is not supported for runtime python3.7",
            str(ex.exception))
Пример #13
0
    def test_must_raise_exception_on_pip_failure(self,
                                                 PythonSubProcessPipMock):
        PythonSubProcessPipMock.side_effect = MissingPipError(
            python_path="mockpath")

        action = PythonPipBuildAction(
            "artifacts",
            "scratch_dir",
            "manifest",
            "runtime",
            {
                "python":
                BinaryPath(resolver=Mock(),
                           validator=Mock(),
                           binary="python",
                           binary_path=sys.executable)
            },
        )

        with self.assertRaises(ActionFailedError):
            action.execute()
Пример #14
0
    def test_must_fail_workflow_binary_resolution_failure(self):
        action_mock = Mock()
        validator_mock = Mock()
        validator_mock.validate = Mock()
        validator_mock.validate.return_value = None
        resolver_mock = Mock()
        resolver_mock.exec_paths = MagicMock(
            side_effect=ValueError("Binary could not be resolved"))
        binaries_mock = Mock()
        binaries_mock.return_value = []

        self.work.get_validators = lambda: validator_mock
        self.work.get_resolvers = lambda: resolver_mock
        self.work.actions = [
            action_mock.action1, action_mock.action2, action_mock.action3
        ]
        self.work.binaries = {
            "binary":
            BinaryPath(resolver=resolver_mock,
                       validator=validator_mock,
                       binary="binary")
        }
        with self.assertRaises(WorkflowFailedError) as ex:
            self.work.run()