def run_with_arguments_should_work_properly() -> None: _additional_value = 'No' _additional_key_word_value = 'What' normal_val = 'one' normal_key_val = 'two' def _function(normal_arg: str, value_one: str, normal_key_arg: str = None, key_value: str = None) -> Any: CommonAssertionUtils.are_equal(value_one, _additional_value) CommonAssertionUtils.are_equal(key_value, _additional_key_word_value) CommonAssertionUtils.are_equal(normal_arg, normal_val) CommonAssertionUtils.are_equal(normal_key_arg, normal_key_val) if normal_arg == normal_val and normal_key_arg == normal_key_val and value_one == _additional_value and key_value == _additional_key_word_value: return True result = CommonFunctionUtils.run_with_arguments( _function, _additional_value, key_value=_additional_key_word_value)( normal_val, normal_key_arg=normal_key_val) CommonAssertionUtils.is_true( result, message='Failed to send proper arguments: {}'.format(result))
def _should_spawn_and_despawn_human_sim_properly() -> None: sim_info = CommonSimSpawnUtils.create_human_sim_info( first_name='Tester', last_name='McTest', source='testing') CommonAssertionUtils.is_true(sim_info is not None) CommonAssertionUtils.is_true( CommonSimSpawnUtils.despawn_sim(sim_info, cause='Was just a test.'))
def _enum_values_result_should_be_correct() -> None: expected_list = [1, 2, 3] result_values = [] for enum_thing in TestEnum.values(): result_values.append(enum_thing) CommonAssertionUtils.list_contents_are_same(result_values, expected_list)
def run_predicate_with_reversed_result_should_work_properly( func_result: bool, expected_result: bool): def _function(*_, **__) -> Any: return func_result result = CommonFunctionUtils.run_predicate_with_reversed_result( _function)() CommonAssertionUtils.are_equal(result, expected_result)
def _should_override_property() -> None: @CommonInjectionUtils.inject_safely_into(ModInfo.get_identity(), FakeClassToBeOverridden, 'the_property') def _overridden_property(*_: Any, **__: Any) -> bool: return True CommonAssertionUtils.is_true(FakeClassToBeOverridden().the_property)
def _enum_should_be_iterable() -> None: expected_list = [ 'TEST_VALUE_ONE', 'TEST_VALUE_TWO', 'TEST_VALUE_THREE' ] result_values = [] for enum_thing in TestEnum: result_values.append(enum_thing) CommonAssertionUtils.list_contents_are_same(result_values, expected_list)
def enum_names_result_should_be_correct(): expected_list = [ 'TEST_VALUE_ONE', 'TEST_VALUE_TWO', 'TEST_VALUE_THREE' ] result_values = [] for enum_thing in TestEnum.names(): result_values.append(enum_thing) CommonAssertionUtils.list_contents_are_same(result_values, expected_list)
def _should_override_instance_method() -> None: @CommonInjectionUtils.inject_safely_into( ModInfo.get_identity(), FakeClassToBeOverridden, FakeClassToBeOverridden.the_instance_method.__name__) def _overridden_instance_method(*_: Any, **__: Any) -> bool: return True CommonAssertionUtils.is_true( FakeClassToBeOverridden().the_instance_method())
def _enum_items_result_should_be_correct() -> None: expected_list = [ TestEnum.TEST_VALUE_ONE, TestEnum.TEST_VALUE_TWO, TestEnum.TEST_VALUE_THREE ] result_values = [] for enum_thing in TestEnum.items(): result_values.append(enum_thing) CommonAssertionUtils.list_contents_are_same(result_values, expected_list)
def _s4cl_sim_types_are_close_enough(sim_type_one: CommonSimType, sim_type_two: CommonSimType, expected_result: bool) -> None: result = CommonSimTypeUtils().are_same_age_and_species( sim_type_one, sim_type_two) CommonAssertionUtils.are_equal( result, expected_result, 'Sim Types were not considered similar when they should be. {} and {}' .format(sim_type_one.name, sim_type_two.name) if expected_result else 'Sim Types were considered similar when they should not be. {} and {}' .format(sim_type_one.name, sim_type_two.name))
def run_predicates_as_one_should_work_properly(func_result_one: bool, func_result_two: bool, all_must_pass: bool, expected_result: bool): def _function_one(*_, **__) -> Any: return func_result_one def _function_two(*_, **__) -> Any: return func_result_two result = CommonFunctionUtils.run_predicates_as_one( (_function_one, _function_two), all_must_pass=all_must_pass)() CommonAssertionUtils.are_equal(result, expected_result)
def _function(normal_arg: str, value_one: str, normal_key_arg: str = None, key_value: str = None) -> Any: CommonAssertionUtils.are_equal(value_one, _additional_value) CommonAssertionUtils.are_equal(key_value, _additional_key_word_value) CommonAssertionUtils.are_equal(normal_arg, normal_val) CommonAssertionUtils.are_equal(normal_key_arg, normal_key_val) if normal_arg == normal_val and normal_key_arg == normal_key_val and value_one == _additional_value and key_value == _additional_key_word_value: return True
def _enum_call_should_throw_when_value_not_found(value: Any): exception = CommonAssertionUtils.throws(lambda: TestEnum(value), value) CommonAssertionUtils.is_true( isinstance(exception, KeyError), message='Exception was not of type KeyError, it was type \'{}\''. format(type(exception))) CommonAssertionUtils.has_length(exception.args, 1) exception_message = exception.args[0] CommonAssertionUtils.are_equal( exception_message, 'Value: \'{}\' not found within class \'TestEnum\''.format(value))
def should_intersect_false(list_one: List[int], *list_items: int): result = CommonCollectionUtils.intersects(list_one, *list_items) CommonAssertionUtils.is_false(result)
def _should_merge_dictionaries_allow_duplicates_false(dictionary_one: Dict[str, Any], dictionary_two: Dict[str, Any]) -> None: result_dict = CommonCollectionUtils.merge_dict(dictionary_one, dictionary_two, allow_duplicates_in_collections=False) CommonAssertionUtils.contains(result_dict, 'a', message=pformat(result_dict)) CommonAssertionUtils.contains(result_dict, 'b', message=pformat(result_dict)) CommonAssertionUtils.contains(result_dict, 'c', message=pformat(result_dict)) CommonAssertionUtils.contains(result_dict, 'test_coll', message=pformat(result_dict)) CommonAssertionUtils.contains(result_dict, 'test_other_coll', message=pformat(result_dict)) a_val = result_dict['a'] CommonAssertionUtils.are_equal(a_val, 5, message=pformat(result_dict)) b_val = result_dict['b'] CommonAssertionUtils.are_equal(b_val, 2, message=pformat(result_dict)) c_val = result_dict['c'] CommonAssertionUtils.are_equal(c_val, 6, message=pformat(result_dict)) test_coll_val = result_dict['test_coll'] CommonAssertionUtils.contains(test_coll_val, 1, message=pformat(result_dict)) CommonAssertionUtils.contains(test_coll_val, 2, message=pformat(result_dict)) CommonAssertionUtils.contains(test_coll_val, 3, message=pformat(result_dict)) CommonAssertionUtils.contains(test_coll_val, 4, message=pformat(result_dict)) CommonAssertionUtils.contains(test_coll_val, 5, message=pformat(result_dict)) CommonAssertionUtils.contains(test_coll_val, 6, message=pformat(result_dict)) count_of_test_val = 0 for val in test_coll_val: if val == 3: count_of_test_val += 1 CommonAssertionUtils.are_equal(count_of_test_val, 1, message='The number of 3s were not correct! {}'.format(pformat(result_dict))) test_other_coll_val = result_dict['test_other_coll'] CommonAssertionUtils.contains(test_other_coll_val, 24, message=pformat(result_dict)) CommonAssertionUtils.contains(test_other_coll_val, 25, message=pformat(result_dict))
def _enum_should_have_value() -> None: CommonAssertionUtils.is_true( hasattr(TestEnum.TEST_VALUE_ONE, 'value'), message='Enum did not have attribute \'value\'') CommonAssertionUtils.are_equal( getattr(TestEnum.TEST_VALUE_ONE, 'value'), 1)
def _get_and_new_should_be_same_instance() -> None: CommonAssertionUtils.is_true(_TestService() is _TestService.get())
def _get_and_new_should_equal_same_instance() -> None: CommonAssertionUtils.are_equal(_TestService(), _TestService.get())
def _sub_service_should_be_separate_instance_from_parent() -> None: CommonAssertionUtils.is_false( _TestSubService.get() is _TestService.get())
def enum_should_convert_properly(enum_val, expected_value): CommonAssertionUtils.are_equal(int(enum_val), expected_value)
def enum_should_have_name(): CommonAssertionUtils.is_true( hasattr(TestEnum.TEST_VALUE_ONE, 'name'), message='Enum did not have attribute \'name\'') CommonAssertionUtils.are_equal( getattr(TestEnum.TEST_VALUE_ONE, 'name'), 'TEST_VALUE_ONE')
def _s4cl_determine_sim_type(species: CommonSpecies, age: CommonAge, occult_type: CommonOccultType, expected_sim_type: CommonSimType): result = CommonSimTypeUtils()._determine_sim_type( species, age, occult_type) CommonAssertionUtils.are_equal(result, expected_sim_type)
def _services_should_not_be_reinitialized_when_retrieved_via_new() -> None: thing_added = 'A thing' _TestService().a_collection_of_things.append(thing_added) CommonAssertionUtils.is_true( thing_added in _TestService().a_collection_of_things)
def should_intersect_true(list_one, *list_items): result = CommonCollectionUtils.intersects(list_one, *list_items) CommonAssertionUtils.is_true(result)
def _enum_should_convert_float_properly(enum_val, expected_value) -> None: CommonAssertionUtils.are_equal(float(enum_val), expected_value)
def _enum_should_convert_string_properly(enum_val, expected_value) -> None: CommonAssertionUtils.are_equal(expected_value, str(enum_val))
def _enum_should_be_gained_via_calling_the_enum_class_by_name( value: Any, expected_value): CommonAssertionUtils.are_equal(TestEnum(value), expected_value)
def should_combine(items: List[int], combination_length: int, expected_outcome: Set[Tuple[int]]): result = CommonCollectionUtils.create_possible_combinations( items, combination_length) CommonAssertionUtils.are_equal(result, expected_outcome)