def test_get_parsers(self, mock_logger): parsers = parser.get_parsers() self.assertTrue('.pltp' in parsers) self.assertTrue('.pl' in parsers) self.assertEqual(len(mock_logger.error.call_args_list), 5) # Check for no duplicate self.assertNotEqual(mock_logger.error.call_args_list[0], mock_logger.error.call_args_list[1]) self.assertNotEqual(mock_logger.error.call_args_list[0], mock_logger.error.call_args_list[2]) self.assertNotEqual(mock_logger.error.call_args_list[1], mock_logger.error.call_args_list[2])
def test_get_type(self, mock_logger): parsers = parser.get_parsers() # Correct paths path1 = "relative/to/pl.pl" path2 = "/absolute/to/pl.pl" path3 = "to/pltp.pltp" path4 = "to/pl_default_ext" # Raise UnknownExtension path5 = "to/test.unknown" self.assertEqual(parser.get_type(self.dir, path1), "pl") self.assertEqual(parser.get_type(self.dir, path2), "pl") self.assertEqual(parser.get_type(self.dir, path3), "pltp") self.assertEqual(parser.get_type(self.dir, path4), "pl") with self.assertRaises(UnknownExtension): parser.get_type(self.dir, path5)
def is_pltp(path): parsers = get_parsers() ext = splitext(path)[1] return ext in parsers and parsers[ext]['type'] == 'pltp'
def is_pltp(path): """Returns True if path is a pltp, False otherwise.""" parsers = get_parsers() ext = os.path.splitext(path)[1] return not os.path.isdir( path) and ext in parsers and parsers[ext]['type'] == 'pltp'