countrydata

countrydata.spec

class countrydata.spec.CountryDataEntity[source]

Base class for all specification fields. All abstract properties are mandatory and must be overwritten for each field specficiation.

abstract classmethod property readable

Readable representation of a field.

abstract classmethod property ids

Valid identifiers for a field. The first identifier defined is the main identifier, and will be exposed as a property of countrydata.spec.Country interface.

abstract classmethod property field_path

Path to the field inside the data. This needs to be defined as path/to/category:location.of.data where path/to/category is the path in the data files tree and location.of.data indicates the JSON attribute where is located the value for the country formatted as Javascript . characters getters syntax.

For example, the location of ISO-3361-1 Alpha2 code values are in countrydata/data/files/general/<country-file>.json:codes.a2, so the value of this property at specification is general:codes.a2.

abstract classmethod property type

Data type of the field. Needs to be a valid builtin python data type. Will be used to cast values and for testing.

abstract classmethod property null

Boolean value that specifies if the field can be nullable or not.

abstract classmethod property assertions

List of tuples of two functions that takes a value as first parameter. Assertions are used to infere what fields are passed on interface initializations and testing the library.

The assertions described here must not contain assertions for type data or nullable values testing because this assertions are included dinamically using null and type properties.

Example of ISO-3361-1 Alpha2 specification assertion:

>>> [
>>>     (
>>>          lambda value: value.isupper(),
>>>          lambda value: "%s code for %s is not uppercased" % (ISO_3361_1_Alpha2.readable, value),
>>>     ),
>>> ]
abstract classmethod property data

Information about data providers and data sources. Represented by a dictionary of, at least, one key:

  • provider* Dictionary with readable and url keys that indicates the data provider of the field.

  • source Dictionary with readable and url keys that indicates the data official source of the field. This value is optional. If not is defined, this means that the provider is the same as the official source of the data.

classmethod property data_provider

Returns the data provider defined at attribute provider of data class property.

classmethod property data_source

Returns the data source defined at attribute source of data class property. If not defined, returns the data provider defined at attribute provider of data class property.

classmethod test(value)[source]

Test using default Python assert statments if a value can be considered a valid value that follows the specification of the field.

Parameters

value (any) – Value to test against the field restrictions.

classmethod pytest(value)[source]

Test using Pytest style statments (assertion, "Failure message") if a value can be considered a valid value that follows the specification of the field.

Parameters

value (any) – Value to test against the field specification restrictions.

classmethod property category_dirpath

Returns the absolute path to the files directory of the category group for the field.

classmethod property categories_chain

Returns all nested categories that belongs to the field specification.

classmethod property groups_chain

Returns all nested groups that wraps the field specification into nested dictionaries.

classmethod filepath(value)[source]

Returns the ISO-3361-1 Alpha2 data filename correspondent to the value passed. Needs to be a valid value for the field of the specification.

Parameters

value (any) – Field specification value to use for search the correspondent ISO-3361-1 Alpha2 data filename.

classmethod random_value()[source]

Returns a random country between the values of specification field.

classmethod property valid_field_names

Returns a list of strings that can be used to initializate the country explicitly by field-value at Country interface.