def setUp(self):
   super(ComparatorTestCase, self).setUp()
   self.comparator = Comparator()
   self.file1 = None
   self.file2 = None
   self.formats = [standards.PROVN, standards.JSON]
   self.config = {Comparator.FORMATS: self.formats}
class ComparatorTestCase(unittest.TestCase):

  def setUp(self):
    super(ComparatorTestCase, self).setUp()
    self.comparator = Comparator()
    self.file1 = None
    self.file2 = None
    self.formats = [standards.PROVN, standards.JSON]
    self.config = {Comparator.FORMATS: self.formats}

  def tearDown(self):
    super(ComparatorTestCase, self).tearDown()
    for tmp in [self.file1, self.file2]:
      if tmp != None and os.path.isfile(tmp):
        os.remove(tmp)

  def test_init(self):
    self.assertEqual([], self.comparator.formats)

  def test_configure(self):
    self.comparator.configure(self.config)
    self.assertEqual(self.formats, self.comparator.formats)

  def test_configure_non_dict_error(self):
    with self.assertRaises(ConfigError):
      self.comparator.configure(123)

  def test_configure_no_formats(self):
    with self.assertRaises(ConfigError):
      self.comparator.configure({})

  def test_configure_non_canonical_format(self):
    self.config[Comparator.FORMATS].append("invalidFormat")
    with self.assertRaises(ConfigError):
      self.comparator.configure(self.config)

  def test_compare_missing_file1(self):
    self.file1 = "nosuchfile." + standards.JSON
    (_, self.file2) = tempfile.mkstemp(suffix="." + standards.JSON)
    with self.assertRaises(ComparisonError):
      self.comparator.compare(self.file1, self.file2)

  def test_compare_missing_file2(self):
    (_, self.file1) = tempfile.mkstemp(suffix="." + standards.JSON)
    self.file2 = "nosuchfile." + standards.JSON
    with self.assertRaises(ComparisonError):
      self.comparator.compare(self.file1, self.file2)

  def test_check_format_invalid_format(self):
    self.comparator.configure(self.config)
    with self.assertRaises(ComparisonError):
      self.comparator.check_format("nosuchformat")