def test_closed_metadata(self):
     reader = Reader(
         'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
     )
     reader.close()
     self.assertRaisesRegex(IOError,
                            'Attempt to read from a closed MaxMind DB.',
                            reader.metadata)
 def test_double_close(self):
     reader = Reader(
         'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
     )
     reader.close()
     self.assertRaisesRegex(IOError,
                            'Attempt to close a closed MaxMind DB.',
                            reader.close)
 def test_closed_get(self):
     reader = Reader(
         'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
     )
     reader.close()
     self.assertRaisesRegex(ValueError,
                            'Attempt to read from a closed MaxMind DB.'
                            '|closed or invalid',
                            reader.get, ('1.1.1.1'))
    def test_closed_metadata(self):
        reader = Reader(
            'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
        )
        reader.close()

        # The primary purpose of this is to ensure the extension doesn't
        # segfault
        try:
            metadata = reader.metadata()
        except IOError as ex:
            self.assertEqual('Attempt to read from a closed MaxMind DB.',
                             str(ex), 'extension throws exception')
        else:
            self.assertIsNotNone(
                metadata, 'pure Python implementation returns value')
 def test_double_close(self):
     reader = Reader(
         'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
     )
     self.assertIsNone(
         reader.close(), 'Double close does not throw an exception')
 def test_close(self):
     reader = Reader(
         'tests/data/test-data/MaxMind-DB-test-decoder.mmdb'
     )
     reader.close()