pycountry
pycountry copied to clipboard
Examples in README.rst don't all work (use doctests?)
A couple of the examples in README.rst
don't work as advertised.
The most important is the one that returns None
rather than the data structure intended:
>>> import pycountry
>>> pycountry.__version__
'23.12.11'
>>> list(pycountry.subdivisions.get(country_code='AL'))
[SubdivisionHierarchy(code='AL-02', country_code='AL', name='Durrës', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-04', country_code='AL', name='Fier', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-06', country_code='AL', name='Korçë', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-08', country_code='AL', name='Lezhë', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-10', country_code='AL', name='Shkodër', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-12', country_code='AL', name='Vlorë', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-05', country_code='AL', name='Gjirokastër', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-01', country_code='AL', name='Berat', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-03', country_code='AL', name='Elbasan', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-07', country_code='AL', name='Kukës', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-09', country_code='AL', name='Dibër', parent_code=None, type='County'), SubdivisionHierarchy(code='AL-11', country_code='AL', name='Tiranë', parent_code=None, type='County')]
>>> al_br = pycountry.subdivisions.get(code='AL-BU')
>>> print(al_br)
None
# is claimed to be a valid subdivision
The returned information for subdivision types may also be different:
>>> de_st = pycountry.subdivisions.get(code='DE-ST')
>>> de_st.type
'Land'
# claimed to be "State"
There are also some numerical differences that are less problematic but still potentially confusing to users.
>>> len(pycountry.subdivisions)
5127
# is claimed to be 4847
>>> len(pycountry.scripts)
182
# claimed to be 169
>>> len(pycountry.languages)
7910
# claimed to be 7874
Perhaps it is possible to use doctest to ensure that these tests remain accurate?