Пример #1
0
    def test_correct_arguments_passed(self, get_target_by_name,
                                      assemble_config, datetime):
        target = mock.Mock()
        target.labels = ["foo"]
        target.features = ["bar"]
        target.components = ["baz"]
        target.macros = ["macbaz"]
        target.device_has = ["stuff"]
        target.core = ["core"]
        target.supported_form_factors = ["arduino"]
        datetime = mock.Mock()
        datetime.datetime.now.return_value.timestamp.return_value = 2
        config = ConfigFactory()
        assemble_config.return_value = config
        get_target_by_name.return_value = target
        mbed_target = "K64F"
        program_path = "blinky"
        toolchain_name = "GCC"

        result = generate_mbed_config_cmake_file(mbed_target, program_path,
                                                 toolchain_name)

        get_target_by_name.assert_called_once_with(mbed_target, program_path)
        assemble_config.assert_called_once_with(mbed_target,
                                                pathlib.Path(program_path))
        self.assertEqual(
            result,
            _render_mbed_config_cmake_template(
                target,
                config,
                toolchain_name,
                mbed_target,
            ),
        )
Пример #2
0
    def test_returns_rendered_content(self):
        config = ConfigFactory()
        result = _render_config_header_template(config)

        for value in config.options.values():
            self.assertIn(value, result)
        for value in config.macros.values():
            self.assertIn(value, result)
Пример #3
0
    def test_correct_arguments_passed(self, assemble_config):
        config = ConfigFactory()
        assemble_config.return_value = config
        mbed_target = "K64F"
        program_path = "mbed_program"

        result = generate_config_header_file(mbed_target, program_path)

        assemble_config.assert_called_once_with(mbed_target, pathlib.Path(program_path))
        self.assertEqual(result, _render_config_header_template(config))
Пример #4
0
    def test_builds(self):
        option = OptionFactory()
        macro = MacroFactory()
        config = ConfigFactory()
        config.options[option.key] = option
        config.macros[macro.name] = macro

        expected_output = (
            "Configuration parameters\n"
            "------------------------\n"
            f'{option.key} = {option.value} (macro name: "{option.macro_name}")\n\n'
            "\n"
            "Macros\n"
            "------\n"
            f"{macro.name}={macro.value}\n"
        )

        result = _build_legacy_output(config)
        self.assertEqual(result, expected_output)
Пример #5
0
    def test_returns_rendered_content(self):
        target = mock.Mock()
        target.labels = ["foo"]
        target.features = ["bar"]
        target.components = ["baz"]
        target.macros = ["macbaz"]
        target.device_has = ["stuff"]
        target.core = ["core"]
        target.supported_form_factors = ["arduino"]
        config = ConfigFactory()
        toolchain_name = "baz"
        result = _render_mbed_config_cmake_template(target, config,
                                                    toolchain_name,
                                                    "target_name")

        for label in target.labels:
            self.assertIn(label, result)

        for macro in target.features + target.components + [toolchain_name]:
            self.assertIn(macro.upper(), result)
Пример #6
0
    def test_builds(self):
        option = OptionFactory()
        macro = MacroFactory()
        config = ConfigFactory()
        config.options[option.key] = option
        config.macros[macro.name] = macro

        parameters_table = tabulate([[option.key, option.macro_name, option.value]], ["key", "macro name", "value"])
        macros_table = tabulate([[macro.name, macro.value]], ["name", "value"])
        expected_output = (
            "PARAMETER CONFIGURATION\n"
            "-----------------------\n"
            f"{parameters_table}\n"
            "\n"
            "MACRO CONFIGURATION\n"
            "-------------------\n"
            f"{macros_table}"
        )

        result = _build_tabular_output(config)
        self.assertEqual(result, expected_output)
Пример #7
0
    def test_builds_value_none(self):
        option = OptionFactory()
        option.value = None
        macro = MacroFactory()
        macro.value = None
        config = ConfigFactory()
        config.options[option.key] = option
        config.macros[macro.name] = macro

        expected_output = (
            "Configuration parameters\n"
            "------------------------\n"
            f"{option.key} has no value\n\n"
            "\n"
            "Macros\n"
            "------\n"
            f"{macro.name}\n"
        )

        result = _build_legacy_output(config)
        self.assertEqual(result, expected_output)
Пример #8
0
    def test_builds(self):
        option = OptionFactory()
        macro = MacroFactory()
        config = ConfigFactory()
        config.options[option.key] = option
        config.macros[macro.name] = macro

        expected_config = {
            "parameters": [
                {
                    "key": option.key,
                    "macro_name": option.macro_name,
                    "value": option.value,
                    "help_text": option.help_text,
                    "set_by": option.set_by,
                }
            ],
            "macros": [{"name": macro.name, "value": macro.value, "set_by": macro.set_by}],
        }

        result = _build_json_output(config)
        self.assertEqual(result, json.dumps(expected_config, indent=4))
Пример #9
0
import pathlib
from unittest import TestCase, mock

from click.testing import CliRunner
from tabulate import tabulate

from mbed_build._internal.mbed_tools.config import (
    config,
    _build_tabular_output,
    _build_json_output,
    _build_legacy_output,
)
from tests._internal.config.factories import ConfigFactory, OptionFactory, MacroFactory


@mock.patch("mbed_build._internal.mbed_tools.config.assemble_config", return_value=ConfigFactory())
class TestConfig(TestCase):
    mbed_target = "K64F"
    program_path = "somewhere"

    def test_config_table(self, assemble_config):
        runner = CliRunner()
        result = runner.invoke(config, ["-m", self.mbed_target, "-p", self.program_path])

        self.assertEqual(result.exit_code, 0)
        self.assertIn(_build_tabular_output(assemble_config.return_value), result.output)
        assemble_config.assert_called_once_with(self.mbed_target, pathlib.Path(self.program_path))

    def test_config_json(self, assemble_config):
        runner = CliRunner()
        result = runner.invoke(config, ["-m", self.mbed_target, "-p", self.program_path, "--format", "json"])