示例#1
0
    def setUp(self):
        self.docker_mock = MagicMock(Docker)
        self.runner_mock = MagicMock(Runner)
        self.file_wrapper_mock = MagicMock(FileWrapper)

        self.config = {"version": "1.0", "a": "b"}
        self.file_wrapper_mock.json_load.return_value = self.config

        self.sut = BcModule(self.docker_mock, self.runner_mock,
                            self.file_wrapper_mock)
示例#2
0
 def __init__(self,
              bc_module=BcModule(),
              config_reader=ConfigReader(),
              extensions=Extensions()):
     self.bc_module = bc_module
     self.config_reader = config_reader
     self.extensions = extensions
示例#3
0
    def __init__(self):
        self.sub_proc = SubProc()
        self.docker = Docker(self.sub_proc)
        self.runner = Runner(self.docker)
        self.file_wrapper = FileWrapper()
        self.bc_module = BcModule(self.docker, self.runner, self.file_wrapper)
        self.git = Git(self.sub_proc)
        self.ui = Ui()

        self.tools = [
            help.Help(self.bc_module),
            update.Update(self.docker),
            version.Version(self.docker),
            ghrn.Ghrn(self.docker),
            docs.Docs(self.docker),
        ]

        self.config_reader = ConfigReader(self.file_wrapper, self.bc_module,
                                          self.tools)
示例#4
0
 def __init__(self, file_wrapper=FileWrapper(), bc_module=BcModule()):
     self.file_wrapper = file_wrapper
     self.bc_module = bc_module
示例#5
0
class BcModuleTest(unittest.TestCase):
    def setUp(self):
        self.docker_mock = MagicMock(Docker)
        self.runner_mock = MagicMock(Runner)
        self.file_wrapper_mock = MagicMock(FileWrapper)

        self.config = {"version": "1.0", "a": "b"}
        self.file_wrapper_mock.json_load.return_value = self.config

        self.sut = BcModule(self.docker_mock, self.runner_mock,
                            self.file_wrapper_mock)

    def test_read_config_reads_config(self):
        # Fixture
        path = "/module/root"

        # Test
        actual = self.sut.read_config(path)

        # Assert
        self.assertEqual("b", actual['a'])
        self.file_wrapper_mock.json_load.assert_called_once_with(
            path + '/module.json')

    def test_read_config_reads_raises_exception_on_missing_version(self):
        # Fixture
        self.file_wrapper_mock.json_load.return_value = {}

        # Assert
        with self.assertRaises(ToolbeltException):
            # Test
            self.sut.read_config("/module/root")

    def test_execute_tool(self):
        # Fixture
        path_to_root = 'pathToRoot'
        module_root_in_docker_host = "moduleRootInDockerHost"
        module_config = {"version": "1.0", "a": "b"}
        tb_config = {
            'module_root': path_to_root,
            'module_root_in_docker_host': module_root_in_docker_host
        }
        command = 'cmd'
        arguments = ['a1']

        self.file_wrapper_mock.json_load.return_value = module_config

        # Test
        self.sut.execute_tool(tb_config, command, arguments)

        # Assert
        self.runner_mock.run_script_in_env.assert_called_once_with(
            tb_config, module_config, 'tools/build/' + command,
            module_root_in_docker_host, arguments)

    def test_enumerate_tools(self):
        # Fixture
        with patch('os.listdir') as mock:
            module_root = "moduleRoot"
            expected = ['result']
            mock.return_value = expected

            # Test
            actual = self.sut.enumerate_tools(module_root)

            # Assert
            self.assertEqual(expected, actual)
            mock.assert_called_once_with(module_root + "/tools/build")

    def test_enumerate_tools_nothing_found(self):
        # Fixture
        with patch('os.listdir') as mock:
            module_root = "moduleRoot"
            mock.side_effect = OSError()

            # Test
            actual = self.sut.enumerate_tools(module_root)

            # Assert
            self.assertEqual([], actual)

    def test_verify_config_version_returns_on_OK_version(self):
        # Fixture

        # Test
        self.sut.verify_config_version({'version': '1.0'})

        # Assert

    def test_verify_config_version_raises_exception_on_missing_version(self):
        # Fixture

        # Assert
        with self.assertRaises(ToolbeltException):
            # Test
            self.sut.verify_config_version({})

    def test_verify_config_version_raises_exception_on_wrong_version(self):
        # Fixture

        # Assert
        with self.assertRaises(ToolbeltException):
            # Test
            self.sut.verify_config_version({'version': '2.0'})
示例#6
0
文件: help.py 项目: vvinhe/toolbelt
 def __init__(self, bc_module=BcModule()):
     self.bc_module = bc_module