def test_get__returns_none_with_empty_config(self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] config = CMakeProjectConfig() value = config.get(cmake_define_alias) assert value is None assert config.cmake_defines.get(cmake_define_name) is None assert cmake_define_alias not in config.data assert cmake_define_name not in config.cmake_defines
def test_contains__returns_true_if_stored_in_cmake_defines( self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] config = CMakeProjectConfig() config.cmake_defines[cmake_define_name] = "__ANY_VALUE" outcome = cmake_define_alias in config assert outcome is True # -- SANITY-CHECKS: assert cmake_define_alias not in config.data assert cmake_define_name in config.cmake_defines
def test_get__returns_value_with_non_empty_config(self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] expected_value = "value_1:{0}".format(cmake_define_alias.upper()) data = dict() data[cmake_define_alias] = expected_value config = CMakeProjectConfig(data) value = config.get(cmake_define_alias) assert value == expected_value assert config.cmake_defines[cmake_define_name] == expected_value assert cmake_define_alias not in config.data assert cmake_define_name in config.cmake_defines
def test_ctor__kwargs_can_override_data(self): data = dict(one=1) kwargs = dict(one=2) project_data = CMakeProjectConfig(data.copy(), **kwargs) # assert project_data.data != data assert project_data.data["one"] == kwargs["one"] assert project_data.data["one"] != data["one"]
def test_ctor__kwargs_can_extend_data(self): data = dict(one=1) kwargs = dict(two=2) project_data = CMakeProjectConfig(data.copy(), **kwargs) initial_size = len(CMAKE_CONFIG_DEFAULTS) assert project_data.data != data assert len(project_data.data) == initial_size + 2 assert project_data.data["one"] == 1 assert project_data.data["two"] == 2
def test_contains__returns_false_if_not_stored_in_cmake_defines( self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] config = CMakeProjectConfig() outcome = cmake_define_alias in config assert outcome is False # -- SANITY-CHECKS: assert cmake_define_alias not in config.data assert cmake_define_name not in config.cmake_defines
def test_setitem__stores_value_in_cmake_defines(self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] value = "value:{0}".format(cmake_define_alias.upper()) config = CMakeProjectConfig() config[cmake_define_alias] = value stored_value = config[cmake_define_alias] assert config.cmake_defines[cmake_define_name] == value assert cmake_define_alias not in config.data assert value == stored_value
def test_ctor__without_data_contains_default_values(self): project_data = CMakeProjectConfig() expected = CMAKE_CONFIG_DEFAULTS assert project_data.data assert len(project_data.data) == len(CMAKE_CONFIG_DEFAULTS) assert project_data.data == expected assert "cmake_generator" in project_data assert "cmake_parallel" in project_data assert "cmake_defines" in project_data assert "cmake_init_args" in project_data assert "cmake_build_args" in project_data
def test_set_attribute__stores_value_in_cmake_defines( self, cmake_define_alias): cmake_define_name = CMakeProjectConfig.CMAKE_DEFINE_ALIASES[ cmake_define_alias] value = "value_2:{0}".format(cmake_define_alias.upper()) config = CMakeProjectConfig() setattr(config, cmake_define_alias, value) stored_value = getattr(config, cmake_define_alias) assert config.cmake_defines[cmake_define_name] == value assert cmake_define_alias not in config.data assert value == stored_value
def test_same_as__returns_true_with_excluded(self, data1, data2, excluded): config1 = CMakeProjectConfig(data1) config2 = CMakeProjectConfig(data2) outcome1 = config1.same_as(config2, excluded=excluded) outcome2 = config2.same_as(config1, excluded=excluded) assert outcome1 is True assert outcome1 == outcome2
def make_build_config_defaults(config): cmake_defines_items0 = cmake_defines_normalize(config.cmake_defines or []) build_config_defaults = CMakeProjectConfig().data build_config_defaults[ "cmake_generator"] = config.cmake_generator or "ninja" build_config_defaults["cmake_toolchain"] = config.cmake_toolchain build_config_defaults["cmake_build_type"] = None build_config_defaults[ "cmake_install_prefix"] = config.cmake_install_prefix or None # build_config_defaults["cmake_defines"] = [] # MAYBE: ctx.config.cmake_defines build_config_defaults["cmake_defines"] = OrderedDict(cmake_defines_items0) build_config_defaults["build_dir_schema"] = config.build_dir_schema return build_config_defaults
def test_same_as__outcome_is_independent_of_ordering( self, expected, data1, data2): config1 = CMakeProjectConfig(data1) config2 = CMakeProjectConfig(data2) outcome1 = config1.same_as(config2) outcome2 = config2.same_as(config1) assert outcome1 == outcome2 assert expected == outcome1
def test_equals__can_compare_with_other_dict(self, data1, data2, case): project_data1 = CMakeProjectConfig(data1) data2.update(CMAKE_CONFIG_DEFAULTS) assert project_data1 != data2, "CASE: %s" % case
def test_equals__with_other_data_and_deep_diff(self, data1, data2, case): project_data1 = CMakeProjectConfig(data1) project_data2 = CMakeProjectConfig(data2) assert project_data1 != project_data2, "CASE: %s" % case
def test_equals__with_same_data(self, data): project_data1 = CMakeProjectConfig(data) project_data2 = CMakeProjectConfig(data=data.copy()) assert project_data1 == project_data2 assert project_data1.data is not project_data2.data
def test_same_as__returns_false_with_other_data(self, data1, data2, case): config1 = CMakeProjectConfig(data1) config2 = CMakeProjectConfig(data2) outcome = config1.same_as(config2) assert outcome is False, "CASE: %s" % case