Skip to content

Commit

Permalink
Testing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mborsetti committed Apr 25, 2021
1 parent 0fda7a5 commit 2486d9e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ If you can provide a change as a pull request, please do so. If not, please open
Please provide as many links to primary sources (e.g. ICAO, national aviation authority, IATA, etc.) as you can to
help out in the verification process.

P.S. Python contributors can test changes locally with
P.S. Python contributors can test changes locally with ``tox`` or:

.. code-block:: bash
pip install -U airportsdata[testing]
pytest test.py
pytest tests/ -v
Thanks for already contributing to:
Thanks to the following for already contributing:

* `Edward Weymouth <https://github.com/ed42311>`
* `Edward Weymouth <https://github.com/ed42311>`__
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This project is a fork of https://github.com/mwgg/Airports

Python
======
|version| |support| |CI| |issues| |coveralls|
|version| |support| |CI| |coveralls| |issues|

Install from `PyPi <https://pypi.org/project/airportsdata/>`__ using pip:

Expand All @@ -90,7 +90,7 @@ Raw data
========

A CSV (comma separated values) file with headers (UTF-8 encoding) is downloadable from GitHub `here
<https://github.com/mborsetti/airportsdata/raw/main/airportsdata/airports.csv>`__
<https://github.com/mborsetti/airportsdata/raw/main/airportsdata/airports.csv>`__.

License
=======
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
f'{".".join(str(v) for v in project.__min_python_version__)} or newer.\n'
f'You are running {sys.version}')

# requirements = list(map(str.strip, open('requirements.txt').readlines()))
requirements = ['typing_extensions; python_version < "3.8"']
# requirements_testing = list(map(str.strip, open('tests/requirements_testing.txt').readlines()))
requirements_testing = ['backports.zoneinfo; python_version < "3.9"',
'pytest',
'pytest-cov',
'tzdata; os_name == "nt"']
README_rst = open('README.rst').read()

SETUP = {
Expand Down Expand Up @@ -46,6 +52,7 @@
# 'exclude_package_data': {},
'install_requires': requirements,
# 'entry_points': {},
'extras_require': {'testing': requirements_testing},
'python_requires': f'>={".".join(str(v) for v in project.__min_python_version__)}',
'project_urls': {'Bug Tracker': f'{project.__url__.rstrip("//")}/issues',
'Source Code': project.__url__,
Expand Down
29 changes: 20 additions & 9 deletions tests/airportsdata_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Tests"""

import sys
import warnings

import pytest

import airportsdata

try:
from zoneinfo import ZoneInfo
except ImportError:
from backports.zoneinfo import ZoneInfo

py39_only = pytest.mark.skipif(sys.version_info < (3, 7), reason='Only checking data integrity once with latest Python')


airports = airportsdata.load()
airports_iata = airportsdata.load('IATA')
iso_3166_1 = [
Expand Down Expand Up @@ -56,8 +61,13 @@
'Zulu'] # from https://www.php.net/timezones.others 2020-11-08; UTC kept in the list as it's non-geographical


def test_data():
"""Test integrity of the data"""
def test_loading():
assert airportsdata.load()


@py39_only
def test_data_quality():
"""Test quality of the data"""
for key, airport in airports.items():
assert key == airport['icao']
assert airport['icao'].isupper() and len(airport['icao']) in (4, 3)
Expand All @@ -79,8 +89,9 @@ def test_data():
f'(see https://github.com/eggert/tz/blob/master/backward)'))


@py39_only
def test_iata_integrity():
"""Test that there are no IATA code duplicates and that the function works correctly"""
"""Test that there are no IATA code duplicates and that the function works correctly."""
iata = [airport['iata'] for airport in airports.values() if airport['iata']]
assert len(iata) == len(set(iata)) # no duplicate
assert list(airports_iata.keys()) == iata # items returned is identical to those we just built
Expand All @@ -95,8 +106,8 @@ def test_iata_integrity():
# assert report.get_statistics('E') == [], 'Flake8 found violations'


def test_print_database_size():
"""Print database size"""
print()
print(f'Number of airports : {len(airports):6,}')
print(f'Number of IATA codes: {len(airports_iata):6,}')
@py39_only
def test_is_sorted():
"""Test that database is sorted alphabetically."""
airports = airportsdata.load()
assert list(airports.keys()) == sorted(airports.keys())
17 changes: 10 additions & 7 deletions update_readme_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
icao_count = len(airportsdata.load('ICAO'))
iata_count = len(airportsdata.load('IATA'))

print(f'Updating counts in README.rst to ICAO={icao_count} IATA={iata_count}')

with open('README.rst') as f:
README_rst = f.read()
README_rst = README_rst.splitlines(keepends=True)
out_lines = []
for line in README_rst:
if line.startswith('.. |ICAO| replace::'):
line = f'.. |ICAO| replace:: {icao_count:6}'
elif line.startswith('.. |ICAO| replace::'):
line = f'.. |ICAO| replace:: {iata_count:6}'
README_rst = ''.join(README_rst)
with open('README.rst', 'w') as f:
line = f'.. |ICAO| replace:: {icao_count:,}\n'
elif line.startswith('.. |IATA| replace::'):
line = f'.. |IATA| replace:: {iata_count:,}\n'
out_lines.append(line)
README_rst = ''.join(out_lines)
with open('README.rst', 'w', newline='\n') as f:
f.write(README_rst)

print(f'Updated counts of entries in README.rst to ICAO={icao_count:,} '
f'and IATA={iata_count:,}')

0 comments on commit 2486d9e

Please sign in to comment.