Example #1
0
    def test_with_urban(self):
        """Give a file containing urban entities as well."""

        cities = french_city_suggest.prepare_cities(
            self.testdata_folder, urban_entities_filename=self.urbans_xls)
        self.assertEqual([
            {
                'objectID': '01002',
                'cityId': '01002',
                'name': "L'Abergement-de-Varey",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'urban': 0,
            },
            {
                'objectID': '69386',
                'cityId': '69123',
                'name': 'Lyon 6e  Arrondissement',
                'departementId': '69',
                'departementName': 'Rhône',
                'departementPrefix': 'dans le ',
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'urban': 7,
            },
        ], cities[1:3])
Example #2
0
    def test_with_stats(self):
        """Give a file containing stats as well."""

        cities = french_city_suggest.prepare_cities(
            self.testdata_folder, stats_filename=self.stats_csv)
        self.assertEqual([
            {
                'objectID': '01001',
                'cityId': '01001',
                'name': "L'Abergement-Clémenciat",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'population': 784,
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'zipCode': '01400',
            },
            {
                'objectID': '01002',
                'cityId': '01002',
                'name': "L'Abergement-de-Varey",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'population': 221,
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'zipCode': '01640',
            },
        ], cities[:2])
Example #3
0
    def test_with_transport(self):
        """Give a file containing transport scores as well."""

        cities = french_city_suggest.prepare_cities(
            self.testdata_folder,
            transport_scores_filename=self.transports_html)
        self.assertEqual([
            {
                'objectID': '01002',
                'cityId': '01002',
                'name': "L'Abergement-de-Varey",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'transport': 0.0,
            },
            {
                'objectID': '69386',
                'cityId': '69123',
                'name': 'Lyon 6e  Arrondissement',
                'departementId': '69',
                'departementName': 'Rhône',
                'departementPrefix': 'dans le ',
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'transport': 8.85,
            },
        ], cities[1:3])
Example #4
0
    def test_basic_usage(self):
        """Basic Usage."""

        cities = french_city_suggest.prepare_cities(self.testdata_folder)
        self.assertEqual([
            {
                'objectID': '01001',
                'cityId': '01001',
                'name': "L'Abergement-Clémenciat",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
            },
            {
                'objectID': '01002',
                'cityId': '01002',
                'name': "L'Abergement-de-Varey",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
            },
        ], cities[:2])
        lyon_6 = next(c for c in cities if c.get('objectID') == '69386')
        self.assertEqual('Lyon 6e  Arrondissement', lyon_6.get('name'))
        self.assertEqual('69123', lyon_6.get('cityId'))
        self.assertFalse(sum(1 for c in cities
                             if c.get('objectID') == '69123'))
Example #5
0
    def test_with_stats(self) -> None:
        """Give a file containing stats as well."""

        cities = french_city_suggest.prepare_cities(
            self.testdata_folder, stats_filename=self.stats_csv)

        # Point check for coordinates.
        abergement = next(c for c in cities if c.get('objectID') == '01001')
        self.assertAlmostEqual(4.91667, abergement.get('longitude', 0))
        self.assertAlmostEqual(46.15, abergement.get('latitude', 0))
        # Drop coordinates, since we can't check them precisely.
        for city in cities:
            del city['latitude']
            del city['longitude']

        self.assertEqual([
            {
                'objectID': '01001',
                'cityId': '01001',
                'name': "L'Abergement-Clémenciat",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'population': 784,
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'zipCode': '01400',
            },
            {
                'objectID': '01002',
                'cityId': '01002',
                'name': "L'Abergement-de-Varey",
                'departementId': '01',
                'departementName': 'Ain',
                'departementPrefix': "dans l'",
                'population': 221,
                'regionId': '84',
                'regionName': 'Auvergne-Rhône-Alpes',
                'zipCode': '01640',
            },
        ], cities[:2])