def test_escaping_sequences_are_ignored_by_file_reader(self):
     content_with_empty_lines = "\tGeorge, Beth, \f  \f Anne" \
                                "\n      " \
                                "\n           " \
                                "\nRick, Anne,    \v Steph        " \
                                "\n     " \
                                "\n\tAnne,     Beth\r" \
                                "\nSteph, George, Rick" \
                                "\n        \t              \t\t\nAlex, \vBob"
     players_txt_file = self.path_to_players_files + 'players.txt'
     utils.clear_the_content_of_the_desired_file(players_txt_file)
     utils.write_some_content_in_the_desired_file(players_txt_file,
                                                  content_with_empty_lines)
     dict_of_players = self.file_reader.turn_the_file_into_dict(
         players_txt_file)
     print(dict_of_players)
     expected_dict = {
         'George': ['Anne', 'Beth'],
         'Rick': ['Anne', 'Steph'],
         'Anne': ['Beth'],
         'Steph': ['George', 'Rick'],
         'Alex': ['Bob']
     }
     comparison_result = utils.compare_two_dicts(dict_of_players,
                                                 expected_dict)
     self.assertTrue(comparison_result)
 def test_file_is_correctly_read_by_player_filer_reader(self):
     players_txt_file = self.path_to_players_files + 'players.txt'
     utils.clear_the_content_of_the_desired_file(players_txt_file)
     utils.write_some_content_in_the_desired_file(players_txt_file,
                                                  self.content_to_write)
     read_content_of_the_desired_file = \
         self.file_reader.read_the_content_of_the_file_and_return_it_as_list(players_txt_file)
     found_content = ''.join(read_content_of_the_desired_file)
     self.assertEqual(found_content, self.content_to_write)
 def test_max_players_calculator_works_for_standard_entries_when_processing_single_file_with_result_3(
         self):
     content_to_write = 'George, Beth,  Sue\nRick, Anne\nAnne, Beth\nBeth, Anne, George\nSue, Beth'
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     result = self.calculator.calculate_max_number_of_players_touching_a_ball(
         file=self.players_file)
     self.assertEqual(3, result)
 def test_the_validator_recognizes_if_a_dict_does_not_consist_of_players_with_similar_names(
         self):
     content = "Chris, Beth, Stuart\n Becky, Chris\nBeth, Chris, Beth\n\t\tStuart, Chris\nIsis, Chris, Stuart"
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file, content)
     gained_dict = self.file_reader.turn_the_file_into_dict(
         self.players_file)
     result = self.format_validator.check_the_file_does_not_contain_the_same_player_names(
         content, gained_dict)
     self.assertEqual(result, True)
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            self.content_to_write)
 def test_appropriate_message_is_returned_when_desired_file_is_not_found(
         self):
     absolute_path = os.path.abspath(
         '../resources/players_files/players.txt')
     os.remove(absolute_path)
     exp_result = '................................................................................'\
                  '\nTHERE ARE NO FILES IN THE DESIRED DIRECTORY %s' \
                  '\nCREATE A FILE e.g. players.txt' % self.path_to_players_files
     with self.assertRaises(ValueError) as error:
         self.file_reader.check_the_players_files_exist_and_are_correct(
             self.path_to_players_files)
     self.assertEqual(str(error.exception), exp_result)
     utils.write_some_content_in_the_desired_file(self.players_file,
                                                  self.content_to_write)
 def test_max_players_calculator_works_for_standard_entries_when_processing_single_file_with_result_5(
         self):
     content_to_write = 'Adam, \t\tDominic,  Rob,\tIsla' \
                        '\nIsla, Adam' \
                        '\nDominic, \t       Tessy, Rob' \
                        '\nRob,         Adam,   \tDominic' \
                        '\nTessy,           Dominic' \
                        '\nBlaise, Adam'
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     result = self.calculator.calculate_max_number_of_players_touching_a_ball(
         file=self.players_file)
     self.assertEqual(5, result)
 def test_program_returns_an_error_message_when_players_file_exists_but_its_empty(
         self):
     utils.clear_the_content_of_the_desired_file(self.players_file)
     exp_message = '................................................................................' \
                   '\nMAKE SURE THE FILES IN THE /resources/players_file DIRECTORY have any data in them'\
                   '\nFollow the following format for putting data in the files'\
                   '\nMyPlayer, OtherPlayer1, OtherPlayer2, OtherPlayer3 - names should be in'\
                   ' alphanumerics only'\
                   '\n...............................................................................'
     with self.assertRaises(ValueError) as error:
         self.file_reader.read_the_content_of_the_file_and_return_it_as_list(
             self.players_file)
     self.assertEqual(str(error.exception), exp_message)
     utils.write_some_content_in_the_desired_file(self.players_file,
                                                  self.content_to_write)
 def test_max_players_calculator_works_for_standard_entries_when_processing_single_file_with_result_6(
         self):
     content_to_write = 'Harry,            Hermione,  Cedric' \
                        '\nHermione, Cedric           , Malfoy' \
                        '\nCedric,   Harry, \t Lily' \
                        '\nMalfoy,         Cedric,\t\tPeter' \
                        '\nLily,           Cedric' \
                        '\nPeter, Hermione, Malfoy,Queenie' \
                        '\nQueenie,         Peter, Malfoy'
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     result = self.calculator.calculate_max_number_of_players_touching_a_ball(
         file=self.players_file)
     self.assertEqual(6, result)
 def test_max_players_calculator_returns_an_error_when_the_players_file_is_empty(
         self):
     content_to_write = ''
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     exp_result = '................................................................................' \
                  '\nTHE DESIRED FILE IS EMPTY. POPULATE IT WITH DATA AND TRY AGAIN.' \
                  '\nTO POPULATE THE FILE, USE THIS FORMAT: YourPlayer, OtherPlayer1, OtherPlayer2' \
                  '\nUSE ALPHANUMERIC CHARACTERS ONLY!' \
                  '\n...............................................................................'
     with self.assertRaises(ValueError) as error:
         self.calculator.calculate_max_number_of_players_touching_a_ball(
             file=self.players_file)
     self.assertEqual(str(error.exception), exp_result)
 def test_there_cannot_be_two_or_more_players_defined_with_the_same_names(
         self):
     content = "Chris, Beth, Stuart\n Beth, Chris\nBeth, Chris, Steph\n\t\tStuart, Chris"
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file, content)
     gained_dict = self.file_reader.turn_the_file_into_dict(
         self.players_file)
     exp_result = '\n................................................................................'\
                  '\nTHERE CANNOT BE TWO PLAYERS WITH THE SAME NAMES' \
                  '\nCHANGE THE NAMES OF DUPLICATED PLAYERS' \
                  '\n................................................................................'
     with self.assertRaises(ValueError) as error:
         self.format_validator.check_the_file_does_not_contain_the_same_player_names(
             content, gained_dict)
     self.assertEqual(str(error.exception), exp_result)
 def test_file_reader_realises_the_players_file_is_empty_and_returns_appropriate_message(
         self):
     players_txt_file = self.path_to_players_files + 'players.txt'
     utils.clear_the_content_of_the_desired_file(players_txt_file)
     len_of_content_in_the_players_file = os.stat(players_txt_file).st_size
     self.assertEqual(0, len_of_content_in_the_players_file)
     exp_message = '................................................................................'\
                   '\nTHE DESIRED FILE IS EMPTY. POPULATE IT WITH DATA AND TRY AGAIN.'\
                   '\nTO POPULATE THE FILE, USE THIS FORMAT: YourPlayer, OtherPlayer1, OtherPlayer2'\
                   '\nUSE ALPHANUMERIC CHARACTERS ONLY!'\
                   '\n...............................................................................'
     with self.assertRaises(ValueError) as error:
         self.file_reader.turn_the_file_into_dict(players_txt_file)
     self.assertEqual(str(error.exception), exp_message)
     utils.write_some_content_in_the_desired_file(players_txt_file,
                                                  self.content_to_write)
 def test_file_reader_turns_content_into_the_dictionary(self):
     players_txt_file = self.path_to_players_files + 'players.txt'
     utils.clear_the_content_of_the_desired_file(players_txt_file)
     utils.write_some_content_in_the_desired_file(players_txt_file,
                                                  self.content_to_write)
     dict_of_players = self.file_reader.turn_the_file_into_dict(
         players_txt_file)
     expected_dict = {
         'George': ['Anne', 'Beth'],
         'Rick': ['Anne', 'Steph'],
         'Anne': ['Beth'],
         'Steph': ['George', 'Rick'],
         'Alex': ['Bob']
     }
     comparison_result = utils.compare_two_dicts(dict_of_players,
                                                 expected_dict)
     self.assertTrue(comparison_result)
 def test_file_reader_ignores_empty_lines_in_a_file(self):
     #ignoring empty lines in a file ensures the clarity of the finally returned dict file
     content_with_empty_lines = "\tGeorge, Beth,    Anne\n      \n           \nRick, Anne, Steph        \n     \n" \
                                "\tAnne, Beth\nSteph, George, Rick\n        \t              \t\t\nAlex, Bob"
     players_txt_file = self.path_to_players_files + 'players.txt'
     utils.clear_the_content_of_the_desired_file(players_txt_file)
     utils.write_some_content_in_the_desired_file(players_txt_file,
                                                  content_with_empty_lines)
     dict_of_players = self.file_reader.turn_the_file_into_dict(
         players_txt_file)
     expected_dict = {
         'George': ['Anne', 'Beth'],
         'Rick': ['Anne', 'Steph'],
         'Anne': ['Beth'],
         'Steph': ['George', 'Rick'],
         'Alex': ['Bob']
     }
     comparison_result = utils.compare_two_dicts(dict_of_players,
                                                 expected_dict)
     self.assertTrue(comparison_result)
 def test_max_players_calculator_returns_an_error_when_there_are_players_with_two_similar_names(
         self):
     content_to_write = 'Malfoy,            Hermione,  Cedric' \
                        '\nHermione, Cedric           , Malfoy' \
                        '\nCedric,   Harry, \t Lily' \
                        '\nMalfoy,         Cedric,\t\tPeter' \
                        '\nLily,           Cedric' \
                        '\nCedric, Hermione, Malfoy,Queenie' \
                        '\nQueenie,         Peter, Malfoy'
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     exp_result = '\n................................................................................' \
                  '\nTHERE CANNOT BE TWO PLAYERS WITH THE SAME NAMES' \
                  '\nCHANGE THE NAMES OF DUPLICATED PLAYERS' \
                  '\n................................................................................'
     with self.assertRaises(ValueError) as error:
         self.calculator.calculate_max_number_of_players_touching_a_ball(
             file=self.players_file)
     self.assertEqual(str(error.exception), exp_result)
 def test_max_players_calculator_returns_an_error_when_there_are_empty_spaces_instead_of_names_in_the_file(
         self):
     content_to_write = ' ,            Hermione,  Cedric' \
                        '\nHermione, Cedric           , Malfoy' \
                        '\nCedric,   Harry, \t Lily' \
                        '\n      ,         Cedric,\t\tPeter' \
                        '\n      ,           Cedric' \
                        '\n     , Hermione, Malfoy,Queenie' \
                        '\nQueenie,         Peter, Malfoy'
     clear_the_content_of_the_desired_file(self.players_file)
     write_some_content_in_the_desired_file(self.players_file,
                                            content_to_write)
     exp_result = '\n................................................................................' \
                  '\nTHE NAME OF PLAYERS CANNOT BE BLANK! PLEASE REPLACE THE BLANK SPACES ' \
                  'BEFORE THE FIRST COMMA' \
                  '\nWITH A NAME TYPED IN ALPHANUMERICS e.g. StuartTheLittle, Jess1 or Phoebe112' \
                  '\n................................................................................'
     with self.assertRaises(ValueError) as error:
         self.calculator.calculate_max_number_of_players_touching_a_ball(
             file=self.players_file)
     self.assertEqual(str(error.exception), exp_result)