def test_print_boolean(self): expected_false = '[<o]False@' expected_true = '[<o]True@' result_false = Printy._repr_value(False) result_true = Printy._repr_value(True) self.assertEqual(expected_false, result_false) self.assertEqual(expected_true, result_true)
def test_print_number(self): integer_to_print = 123 float_to_print = 123.45 expected_result_integer = '[c]123@' expected_result_float = '[c]123.45@' result_integer = Printy._repr_value(integer_to_print) result_float = Printy._repr_value(float_to_print) self.assertEqual(expected_result_integer, result_integer) self.assertEqual(expected_result_float, result_float)
def test_pretty_printy_set_pretty_false(self): """ Tests pretty printing a set when 'pretty' parameter is set to False """ set_to_print = {1, 2, 'hello'} expected_result = '{1, 2, \'hello\'}' not_pretty_set = Printy._repr_value(set_to_print, pretty=False) self.assertEqual(expected_result, not_pretty_set)
def test_pretty_printy_list_pretty_false(self): """ Tests pretty printing a list when 'pretty' parameter is set to False """ list_to_print = [1, 2, 'hello'] expected_result = '\[1, 2, \'hello\'\]' not_pretty_list = Printy._repr_value(list_to_print, pretty=False) self.assertEqual(expected_result, not_pretty_list)
def test_pretty_printy_tuple_pretty_false(self): """ Tests pretty printing a tuple when 'pretty' parameter is set to False """ tuple_to_print = (1, 2, 'hello') expected_result = '(1, 2, \'hello\')' not_pretty_tuple = Printy._repr_value(tuple_to_print, pretty=False) self.assertEqual(expected_result, not_pretty_tuple)
def test_pretty_printy_dict_pretty_false(self): """ Tests pretty printing a dict when 'pretty' parameter is set to False """ dict_to_print = {'name': 'John Doe', 'age': 34} expected_result = '{\'name\': \'John Doe\', \'age\': 34}' not_pretty_dict = Printy._repr_value(dict_to_print, pretty=False) self.assertEqual(expected_result, not_pretty_dict)
def test_pretty_printy_sets(self): """ Test pretty printing sets """ set_to_print = {1, 2, 'hello'} expected_result = '{\n [c]1@[<oB],@ [c]2@[<oB],@ [c>]\'hello\'@\n}' pretty_set = Printy._repr_value(set_to_print) self.assertEqual(expected_result, pretty_set)
def test_pretty_printy_tuples(self): """ Test pretty printing tuples """ tuple_to_print = (1, 2, 'hello') expected_result = '(\n [c]1@[<oB],@ [c]2@[<oB],@ [c>]\'hello\'@\n)' pretty_tuple = Printy._repr_value(tuple_to_print) self.assertEqual(expected_result, pretty_tuple)
def test_pretty_print_lists(self): """ Test pretty printing lists """ list_to_print = [1, 2, 'hello'] expected_result = '\[\n [c]1@[<oB],@ [c]2@[<oB],@ [c>]\'hello\'@\n\]' pretty_list = Printy._repr_value(list_to_print) self.assertEqual(expected_result, pretty_list)
def test_pretty_print_dicts(self): """ Test pretty printing dictionaries """ dict_to_print = {'name': 'John Doe', 'age': 34} expected_result = '{\n [n>]\'name\'@: [c>]\'John Doe\'@[<oB],@\n [n>]\'age\'@: [c]34@[<oB],@\n}' pretty_dict = Printy._repr_value(dict_to_print) self.assertEqual(expected_result, pretty_dict)
def test_pretty_print_str_method_of_objects(self): """ Test printing the str method of an object, both not defined and defined """ builtin_obj = int expected_builtin_result = '<class \'int\'>' pretty_builtin = Printy._repr_value(builtin_obj) class Person: def __str__(self): return '[c]I am a person@' custom_str = Person() # Notice how it should not return the escaped character expected_custom_result = '[c]I am a person@' pretty_custom = Printy._repr_value(custom_str) self.assertEqual(expected_builtin_result, pretty_builtin) self.assertEqual(expected_custom_result, pretty_custom)
def test_pretty_custom_str_method_in_dictionary(self): class CustomStrMethod: def __str__(self): return '[rBU]Red Bold Underlined@ and [y]Yellow@' dict_to_print = {'str': CustomStrMethod()} expected_result = '{\n [n>]\'str\'@: [rBU]Red Bold Underlined@ and [y]Yellow@[<oB],@\n}' pretty_dict = Printy._repr_value(dict_to_print) self.assertEqual(expected_result, pretty_dict)
def test_pretty_object_in_dictionary(self): """ Test pretty printing an str method of an object inside a dictionary or any iterable, it should give it a light magenta color """ dict_to_print = {'class': int} expected_result = '{\n [n>]\'class\'@: <class \'int\'>[<oB],@\n}' pretty_dict = Printy._repr_value(dict_to_print) self.assertEqual(expected_result, pretty_dict)
def test_print_none(self): expected_none = '[<o]None@' result_none = Printy._repr_value(None) self.assertEqual(expected_none, result_none)