def test_that_loading_mazefield_can_parse_supported_field_elements(self):
        field_definition = "".join(sorted(DEFINITION_TO_ATTRIBUTES.keys()))

        with mock.patch('game.mazefield.open',
                        mock.mock_open(read_data=field_definition)):
            field = MazeField.load_field('default')
            expected_row = [
                DEFINITION_TO_ATTRIBUTES[c] for c in field_definition
            ]
            self.assertEqual(field.field, [expected_row])
def start_game(mazename=None, playername=None, display=None, loglevel=None, *args, **kwargs):

    logging.basicConfig(
        level=LOGLEVELS.get(loglevel, LOGLEVELS['info']),
        format="%(module)s - %(message)s"
    )
    player = get_player_by_name(playername)
    field = MazeField.load_field(mazename)
    current_game = Game(player=player, field=field, displayname=display)
    try:
        while current_game.play_turn() is False:
            time.sleep(0.1)
    except MaximumTurnsReached:
        print("Maximum turns reached, there must be an easier way to get through the maze")
    else:
        current_game._maze_view.finish(player.name, current_game.get_current_turn())
        print("Awesome! You reached the finish in {} steps".format(current_game.get_current_turn()))
    def test_that_field_of_multiple_lines_can_be_parsed(self):
        field_definition = """
#######
# # #=#
#   # #
#0# # #
###   #
#######
"""
        with mock.patch('game.mazefield.open',
                        mock.mock_open(read_data=field_definition)):
            field = MazeField.load_field('default')
            self.assertEqual(field.field, [
                [Wall, Wall, Wall, Wall, Wall, Wall, Wall],
                [Wall, Path, Wall, Path, Wall, Finish, Wall],
                [Wall, Path, Path, Path, Wall, Path, Wall],
                [Wall, Start, Wall, Path, Wall, Path, Wall],
                [Wall, Wall, Wall, Path, Path, Path, Wall],
                [Wall, Wall, Wall, Wall, Wall, Wall, Wall],
            ])
 def test_that_load_field_returns_a_field_object(self):
     field = MazeField.load_field('default')
     self.assertIsInstance(field, MazeField)
 def test_that_a_RuntimeError_is_raised_when_field_cannot_be_parsed_due_unknown_character(
         self):
     with mock.patch('game.mazefield.open',
                     mock.mock_open(read_data='?')) as mock_open:
         with self.assertRaises(RuntimeError):
             MazeField.load_field('default')
    def test_that_MazeField_is_initiated_with_parsed_data_from_file(self):
        with mock.patch('game.mazefield.MazeField') as mock_mazefield, \
                mock.patch('game.mazefield.open', mock.mock_open(read_data='#')) as mock_open:

            MazeField.load_field('default')
            mock_mazefield.assert_called_once_with([[Wall]])
 def test_that_load_field_raises_runtimeerror_when_no_field_definition_found(
         self):
     with self.assertRaises(RuntimeError):
         with mock.patch('game.mazefield.open',
                         mock.mock_open(read_data='')) as mock_open:
             MazeField.load_field('default')
 def test_that_load_field_raises_ioerror_when_file_does_not_exist(self):
     with self.assertRaises(IOError):
         MazeField.load_field('doesnotexist_field')
 def test_that_load_field_reads_file_with_field_definition(self):
     with mock.patch('game.mazefield.open',
                     mock.mock_open(read_data="#")) as mock_open:
         MazeField.load_field('default')
         mock_open.assert_called_once_with('./fields/default')