def test_parse_with_incorrect_number_of_queries(self): mock_open = mock.mock_open(read_data=self.INCORRECT_NUMBER_OF_QUERIES_INPUT_FILE) with mock.patch('main.open', mock_open, create=True): with self.assertRaises(Exception) as e: parser = Parser() parser.parse('') error_msg = e.exception self.assertEquals(str(error_msg), Parser.INCORRECT_NUMBER_OF_QUERIES_ERROR_MSG)
def test_parse_with_incorrect_input_file(self): mock_open = mock.mock_open(read_data=self.INCORRECT_INPUT_FILE) with mock.patch('main.open', mock_open, create=True): with self.assertRaises(Exception) as e: parser = Parser() parser.parse('') error_msg = e.exception self.assertEquals(str(error_msg), Parser.INCORRECT_FORMAT_OF_FILE_ERROR_MSG)
def test_parse_correct_input_file(self): mock_open = mock.mock_open(read_data=self.CORRECT_INPUT_FILE) with mock.patch('main.open', mock_open, create=True): parser = Parser() parser.parse('') self.assertEqual(parser.cases_list.__len__(), 1) self.assertEqual(parser.cases_list[0].city.dx, 4) self.assertEqual(parser.cases_list[0].city.dy, 4) self.assertEquals(parser.cases_list[0].coffee_shops.__len__(), 5) self.assertIn((1, 1), parser.cases_list[0].coffee_shops) self.assertIn((1, 2), parser.cases_list[0].coffee_shops) self.assertIn((3, 3), parser.cases_list[0].coffee_shops) self.assertIn((4, 4), parser.cases_list[0].coffee_shops) self.assertIn((2, 4), parser.cases_list[0].coffee_shops) self.assertEquals(parser.cases_list[0].queries.__len__(), 3) self.assertIn(1, parser.cases_list[0].queries) self.assertIn(2, parser.cases_list[0].queries) self.assertIn(4, parser.cases_list[0].queries)