<commit_before>import tempfile

from maxminddb.const import MODE_MMAP
from six import PY2

from ichnaea.geocode import GEOCODER
from ichnaea import geoip
from ichnaea.tests.base import (
    GEOIP_BAD_FILE,
    GeoIPTestCase,
)


class TestDatabase(GeoIPTestCase):

    def test_open(self):
        self.assertIsInstance(self.geoip_db, geoip.GeoIPWrapper)

    def test_age(self):
        self.assertTrue(isinstance(self.geoip_db.age, int))
        # the test file is older than two months, but not more than 10 years
        self.assertTrue(self.geoip_db.age > 60)
        self.assertTrue(self.geoip_db.age < 3650)

    def test_c_extension(self):
        self.assertTrue(self.geoip_db.check_extension(),
                        'The C extension was not installed correctly.')

    def test_c_extension_warning(self):
        db = self._open_db(mode=MODE_MMAP)
        self.assertFalse(db.check_extension())
        self.check_raven(['RuntimeError: Maxmind C extension not installed'])

    def test_no_file(self):
        db = self._open_db('')
        self.assertTrue(isinstance(db, geoip.GeoIPNull))
        self.check_raven(['OSError: No geoip filename specified.'])

    def test_open_missing_file(self):
        db = self._open_db('/i/taught/i/taw/a/putty/tat')
        self.assertTrue(isinstance(db, geoip.GeoIPNull))<commit_msg>Try to avoid an intermittent test failure.<commit_after>import os
import shutil
import tempfile

from maxminddb.const import MODE_MMAP
from six import PY2

from ichnaea.geocode import GEOCODER
from ichnaea import geoip
from ichnaea.tests.base import (
    GEOIP_BAD_FILE,
    GeoIPTestCase,
)


class TestDatabase(GeoIPTestCase):

    def test_open(self):
        self.assertIsInstance(self.geoip_db, geoip.GeoIPWrapper)

    def test_age(self):
        self.assertTrue(isinstance(self.geoip_db.age, int))
        # the test file is older than two months, but not more than 10 years
        self.assertTrue(self.geoip_db.age > 60)
        self.assertTrue(self.geoip_db.age < 3650)

    def test_c_extension(self):
        self.assertTrue(self.geoip_db.check_extension(),
                        'The C extension was not installed correctly.')

    def test_c_extension_warning(self):
        db = self._open_db(mode=MODE_MMAP)
        self.assertFalse(db.check_extension())
        self.check_raven(['RuntimeError: Maxmind C extension not installed'])

    def test_no_file(self):
        db = self._open_db('')
        self.assertTrue(isinstance(db, geoip.GeoIPNull))
        self.check_raven(['OSError: No geoip filename specified.'])

    def test_open_missing_file(self):
        tmpdir = tempfile.mkdtemp()
        try:
            filename = os.path.join(tmpdir, 'not_there')
            db = self._open_db(filename)
            self.assertTrue(isinstance(db, geoip.GeoIPNull))
        finally:
            shutil.rmtree(tmpdir)

{'fraction_non_alphanumeric': 0.09505571030640668, 'fraction_numerical': 0.006267409470752089, 'mean_word_length': 3.0925925925925926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600736', 'n_tokens_mistral': 957, 'n_tokens_neox': 923, 'n_words': 195}