def setUp(self): super(ConverterTestCase, self).setUp() self.converter = Converter() self.in_file = None self.out_file = None self.input_formats = [standards.PROVN, standards.JSON] self.output_formats = [standards.PROVX, standards.TTL] self.config = {Converter.INPUT_FORMATS: self.input_formats, Converter.OUTPUT_FORMATS: self.output_formats}
class ConverterTestCase(unittest.TestCase): def setUp(self): super(ConverterTestCase, self).setUp() self.converter = Converter() self.in_file = None self.out_file = None self.input_formats = [standards.PROVN, standards.JSON] self.output_formats = [standards.PROVX, standards.TTL] self.config = {Converter.INPUT_FORMATS: self.input_formats, Converter.OUTPUT_FORMATS: self.output_formats} def tearDown(self): super(ConverterTestCase, self).tearDown() def test_init(self): self.assertEqual([], self.converter.input_formats) self.assertEqual([], self.converter.output_formats) def test_configure(self): self.converter.configure(self.config) self.assertEqual(self.input_formats, self.converter.input_formats) self.assertEqual(self.output_formats, self.converter.output_formats) def test_configure_non_dict_error(self): with self.assertRaises(ConfigError): self.converter.configure(123) def test_configure_no_input_formats(self): del self.config[Converter.INPUT_FORMATS] with self.assertRaises(ConfigError): self.converter.configure(self.config) def test_configure_non_canonical_input_format(self): self.config[Converter.INPUT_FORMATS].append("invalidFormat") with self.assertRaises(ConfigError): self.converter.configure(self.config) def test_configure_no_output_formats(self): del self.config[Converter.OUTPUT_FORMATS] with self.assertRaises(ConfigError): self.converter.configure(self.config) def test_configure_non_canonical_output_format(self): self.config[Converter.OUTPUT_FORMATS].append("invalidFormat") with self.assertRaises(ConfigError): self.converter.configure(self.config) def test_convert_missing_input_file(self): self.in_file = "nosuchfile.json" self.out_file = "convert_missing_input_file." + standards.PROVN with self.assertRaises(ConversionError): self.converter.convert(self.in_file, self.out_file) def test_check_formats_invalid_input_format(self): self.converter.configure(self.config) with self.assertRaises(ConversionError): self.converter.check_formats(standards.PROVX, "nosuchformat") def test_check_formats_invalid_output_format(self): self.converter.configure(self.config) with self.assertRaises(ConversionError): self.converter.check_formats("nosuchformat", standards.PROVX)