meteocatpy 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +33 -0
- package/.gitlab-ci.yml +46 -0
- package/.pre-commit-config.yaml +37 -0
- package/.releaserc +23 -0
- package/.releaserc.toml +14 -0
- package/AUTHORS.md +12 -0
- package/CHANGELOG.md +137 -0
- package/LICENSE +194 -0
- package/README.md +62 -0
- package/filetree.py +48 -0
- package/filetree.txt +48 -0
- package/meteocatpy/README.md +62 -0
- package/meteocatpy/__init__.py +27 -0
- package/meteocatpy/const.py +10 -0
- package/meteocatpy/data.py +140 -0
- package/meteocatpy/exceptions.py +35 -0
- package/meteocatpy/forecast.py +137 -0
- package/meteocatpy/helpers.py +46 -0
- package/meteocatpy/py.typed +0 -0
- package/meteocatpy/stations.py +71 -0
- package/meteocatpy/symbols.py +89 -0
- package/meteocatpy/town.py +61 -0
- package/meteocatpy/townstations.py +99 -0
- package/meteocatpy/variables.py +74 -0
- package/meteocatpy/version.py +2 -0
- package/package.json +23 -0
- package/poetry.lock +3313 -0
- package/pyproject.toml +72 -0
- package/releaserc.json +18 -0
- package/requirements.test.txt +3 -0
- package/setup.cfg +64 -0
- package/setup.py +10 -0
- package/tests/data_test.py +122 -0
- package/tests/import_test.py +18 -0
- package/tests/integration_test_complete.py +77 -0
- package/tests/integration_test_forecast.py +54 -0
- package/tests/integration_test_station_data.py +34 -0
- package/tests/integration_test_stations.py +32 -0
- package/tests/integration_test_symbols.py +68 -0
- package/tests/integration_test_town.py +32 -0
- package/tests/integration_test_town_stations.py +36 -0
- package/tests/integration_test_variables.py +32 -0
package/pyproject.toml
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "meteocatpy"
|
|
3
|
+
version = "0.0.7"
|
|
4
|
+
description = "Script para obtener datos meteorológicos de la API de Meteocat"
|
|
5
|
+
authors = ["figorr <jdcuartero@yahoo.es>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://gitlab.com/figorr/meteocatpy"
|
|
9
|
+
keywords = ['meteocatpy', 'meteocat']
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
[tool.poetry.dependencies]
|
|
13
|
+
python = ">=3.12,<3.13"
|
|
14
|
+
requests = "^2.32.3"
|
|
15
|
+
python-dotenv = "^1.0.1"
|
|
16
|
+
simplejson = "^3.19.3"
|
|
17
|
+
setuptools = "^75.5.0"
|
|
18
|
+
python-semantic-release = "^7.28.1"
|
|
19
|
+
twine = ">=3,<4"
|
|
20
|
+
aiofiles = "^24.1.0"
|
|
21
|
+
voluptuous = "^0.15.2"
|
|
22
|
+
geopy = "^2.4.1"
|
|
23
|
+
tzdata = "^2024.2"
|
|
24
|
+
aiohttp = ">=3.10.11,<4.0.0"
|
|
25
|
+
diskcache = "^5.6.3"
|
|
26
|
+
semantic-release = "^0.1.0"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[tool.semantic_release]
|
|
30
|
+
branch = "master" # Define la rama desde la que se harán los lanzamientos
|
|
31
|
+
version_source = "commit" # Determina la versión basada en los commits
|
|
32
|
+
version_variable = "meteocatpy/version.py:__version__" # Ubicación de la variable de versión
|
|
33
|
+
changelog = { file = "CHANGELOG.md" } # Genera el changelog en el archivo especificado
|
|
34
|
+
upload_to_pypi = false # Sube automáticamente la versión a PyPI
|
|
35
|
+
ci = false # Cambiar a false si no usas CI/CD
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["poetry-core"]
|
|
40
|
+
build-backend = "poetry.core.masonry.api"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
[tool.poetry.dev-dependencies]
|
|
44
|
+
aresponses = "*"
|
|
45
|
+
detox = "*"
|
|
46
|
+
flake8 = "*"
|
|
47
|
+
mypy = "*"
|
|
48
|
+
pydocstyle = "*"
|
|
49
|
+
pylint = "*"
|
|
50
|
+
pytest-aiohttp = "*"
|
|
51
|
+
pytest-cov = "*"
|
|
52
|
+
python-semantic-release = "^7.28.1"
|
|
53
|
+
tox = "*"
|
|
54
|
+
safety = ">=1.8.7"
|
|
55
|
+
black = { version = ">19.10b0", allow-prereleases = true }
|
|
56
|
+
Sphinx = ">=3.5.0,<7.0.0"
|
|
57
|
+
autoapi = ">=2.0.1"
|
|
58
|
+
sphinx-rtd-theme = "^0.5.1"
|
|
59
|
+
m2r2 = ">=0.2.7"
|
|
60
|
+
tomlkit = ">=0.7.0"
|
|
61
|
+
sphinx-autoapi = ">=1.7.0"
|
|
62
|
+
sphinx-copybutton = ">=0.3.1"
|
|
63
|
+
pipdeptree = "^2.2.1"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
[tool.poetry.group.dev.dependencies]
|
|
67
|
+
pyupgrade = "^3.4.0"
|
|
68
|
+
pre-commit = "^3.3.1"
|
|
69
|
+
pytest = "^8.3.3"
|
|
70
|
+
pytest-asyncio = "^0.24.0"
|
|
71
|
+
syrupy = "^4.7.2"
|
|
72
|
+
aioresponses = "^0.7.7"
|
package/releaserc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["master"],
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
"@semantic-release/release-notes-generator",
|
|
6
|
+
"@semantic-release/changelog",
|
|
7
|
+
[
|
|
8
|
+
"@semantic-release/exec",
|
|
9
|
+
{
|
|
10
|
+
"prepareCmd": "python setup.py sdist bdist_wheel",
|
|
11
|
+
"publishCmd": "twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD}"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"@semantic-release/github",
|
|
15
|
+
"@semantic-release/git"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
|
package/setup.cfg
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[coverage:run]
|
|
2
|
+
source =
|
|
3
|
+
meteocatpy
|
|
4
|
+
|
|
5
|
+
[coverage:report]
|
|
6
|
+
exclude_lines =
|
|
7
|
+
pragma: no cover
|
|
8
|
+
raise NotImplemented()
|
|
9
|
+
if __name__ == '__main__':
|
|
10
|
+
main()
|
|
11
|
+
show_missing = true
|
|
12
|
+
|
|
13
|
+
[tool:pytest]
|
|
14
|
+
testpaths = tests
|
|
15
|
+
norecursedirs = .git
|
|
16
|
+
asyncio_mode = auto
|
|
17
|
+
addopts =
|
|
18
|
+
-p syrupy
|
|
19
|
+
--strict
|
|
20
|
+
--cov=meteocatpy
|
|
21
|
+
|
|
22
|
+
[flake8]
|
|
23
|
+
# https://github.com/ambv/black#line-length
|
|
24
|
+
max-line-length = 88
|
|
25
|
+
# E501: line too long
|
|
26
|
+
# W503: Line break occurred before a binary operator
|
|
27
|
+
# E203: Whitespace before ':'
|
|
28
|
+
# D202 No blank lines allowed after function docstring
|
|
29
|
+
# W504 line break after binary operator
|
|
30
|
+
ignore =
|
|
31
|
+
E501,
|
|
32
|
+
W503,
|
|
33
|
+
E203,
|
|
34
|
+
D202,
|
|
35
|
+
W504
|
|
36
|
+
|
|
37
|
+
[isort]
|
|
38
|
+
# https://github.com/timothycrosley/isort
|
|
39
|
+
# https://github.com/timothycrosley/isort/wiki/isort-Settings
|
|
40
|
+
# splits long import on multiple lines indented by 4 spaces
|
|
41
|
+
multi_line_output = 3
|
|
42
|
+
include_trailing_comma=True
|
|
43
|
+
force_grid_wrap=0
|
|
44
|
+
use_parentheses=True
|
|
45
|
+
line_length=88
|
|
46
|
+
indent = " "
|
|
47
|
+
# by default isort don't check module indexes
|
|
48
|
+
not_skip = __init__.py
|
|
49
|
+
# will group `import x` and `from x import` of the same module.
|
|
50
|
+
force_sort_within_sections = true
|
|
51
|
+
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
|
|
52
|
+
default_section = THIRDPARTY
|
|
53
|
+
known_first_party = custom_components,tests
|
|
54
|
+
forced_separate = tests
|
|
55
|
+
combine_as_imports = true
|
|
56
|
+
|
|
57
|
+
[mypy]
|
|
58
|
+
python_version = 3.7
|
|
59
|
+
ignore_errors = true
|
|
60
|
+
follow_imports = silent
|
|
61
|
+
ignore_missing_imports = true
|
|
62
|
+
warn_incomplete_stub = true
|
|
63
|
+
warn_redundant_casts = true
|
|
64
|
+
warn_unused_configs = true
|
package/setup.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
# Leer la versión desde el archivo version.py
|
|
4
|
+
with open("meteocatpy/version.py") as f:
|
|
5
|
+
exec(f.read()) # Ejecuta el archivo version.py para cargar la variable __version__
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name="meteocatpy",
|
|
9
|
+
version=__version__, # Usa la versión cargada dinámicamente # type: ignore
|
|
10
|
+
)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
from aioresponses import aioresponses
|
|
4
|
+
from meteocatpy.data import MeteocatStationData
|
|
5
|
+
from meteocatpy.exceptions import (
|
|
6
|
+
BadRequestError,
|
|
7
|
+
ForbiddenError,
|
|
8
|
+
TooManyRequestsError,
|
|
9
|
+
InternalServerError,
|
|
10
|
+
UnknownAPIError,
|
|
11
|
+
)
|
|
12
|
+
from meteocatpy.const import BASE_URL, STATION_DATA_URL
|
|
13
|
+
from dotenv import load_dotenv
|
|
14
|
+
|
|
15
|
+
# Cargar variables desde el archivo .env
|
|
16
|
+
load_dotenv()
|
|
17
|
+
|
|
18
|
+
# Obtener los valores del archivo .env
|
|
19
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
20
|
+
STATION_CODI_TEST = os.getenv("STATION_CODI_TEST")
|
|
21
|
+
|
|
22
|
+
# Asegúrate de que las variables estén definidas
|
|
23
|
+
assert API_KEY, "API Key is required"
|
|
24
|
+
assert STATION_CODI_TEST, "Station codi test is required"
|
|
25
|
+
|
|
26
|
+
@pytest.mark.asyncio
|
|
27
|
+
async def test_get_station_data():
|
|
28
|
+
# Simular la respuesta de la API
|
|
29
|
+
test_url = f"{BASE_URL}{STATION_DATA_URL}".format(
|
|
30
|
+
codiEstacio=STATION_CODI_TEST, any=2024, mes="12", dia="04"
|
|
31
|
+
)
|
|
32
|
+
mock_response = {
|
|
33
|
+
"lectures": [
|
|
34
|
+
{"codi_variable": 32, "data": "2024-12-04T12:00:00Z", "valor": 15.2},
|
|
35
|
+
{"codi_variable": 33, "data": "2024-12-04T12:00:00Z", "valor": 80},
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
with aioresponses() as mock:
|
|
40
|
+
mock.get(test_url, payload=mock_response)
|
|
41
|
+
|
|
42
|
+
station_data = MeteocatStationData(API_KEY)
|
|
43
|
+
result = await station_data.get_station_data(STATION_CODI_TEST)
|
|
44
|
+
|
|
45
|
+
assert result == mock_response
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.asyncio
|
|
49
|
+
async def test_get_station_data_with_variables(mocker):
|
|
50
|
+
# Simular la respuesta de la API y las variables
|
|
51
|
+
test_url = f"{BASE_URL}{STATION_DATA_URL}".format(
|
|
52
|
+
codiEstacio=STATION_CODI_TEST, any=2024, mes="12", dia="04"
|
|
53
|
+
)
|
|
54
|
+
mock_station_response = {
|
|
55
|
+
"lectures": [
|
|
56
|
+
{"codi_variable": 32, "data": "2024-12-04T12:00:00Z", "valor": 15.2},
|
|
57
|
+
{"codi_variable": 33, "data": "2024-12-04T12:00:00Z", "valor": 80},
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
mock_variables_response = [
|
|
61
|
+
{"codi": 32, "nom": "Temperatura"},
|
|
62
|
+
{"codi": 33, "nom": "Humedad relativa"},
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
# Mockear la llamada a la API y las variables
|
|
66
|
+
with aioresponses() as mock:
|
|
67
|
+
mock.get(test_url, payload=mock_station_response)
|
|
68
|
+
mocker.patch(
|
|
69
|
+
"meteocatpy.data.MeteocatVariables.get_variables",
|
|
70
|
+
return_value=mock_variables_response,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
station_data = MeteocatStationData(API_KEY)
|
|
74
|
+
result = await station_data.get_station_data_with_variables(STATION_CODI_TEST)
|
|
75
|
+
|
|
76
|
+
# Validar los datos organizados por variables
|
|
77
|
+
expected_result = {
|
|
78
|
+
"Temperatura": [
|
|
79
|
+
{
|
|
80
|
+
"data": "2024-12-04T12:00:00Z",
|
|
81
|
+
"valor": 15.2,
|
|
82
|
+
"estat": "",
|
|
83
|
+
"base_horaria": "",
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"Humedad relativa": [
|
|
87
|
+
{
|
|
88
|
+
"data": "2024-12-04T12:00:00Z",
|
|
89
|
+
"valor": 80,
|
|
90
|
+
"estat": "",
|
|
91
|
+
"base_horaria": "",
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
}
|
|
95
|
+
assert result == expected_result
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@pytest.mark.asyncio
|
|
99
|
+
async def test_get_station_data_errors():
|
|
100
|
+
test_url = f"{BASE_URL}{STATION_DATA_URL}".format(
|
|
101
|
+
codiEstacio=STATION_CODI_TEST, any=2024, mes="12", dia="04"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Simular errores de la API
|
|
105
|
+
with aioresponses() as mock:
|
|
106
|
+
mock.get(test_url, status=400, payload={"message": "Bad Request"})
|
|
107
|
+
station_data = MeteocatStationData(API_KEY)
|
|
108
|
+
|
|
109
|
+
with pytest.raises(BadRequestError):
|
|
110
|
+
await station_data.get_station_data(STATION_CODI_TEST)
|
|
111
|
+
|
|
112
|
+
mock.get(test_url, status=403, payload={"message": "Forbidden"})
|
|
113
|
+
with pytest.raises(ForbiddenError):
|
|
114
|
+
await station_data.get_station_data(STATION_CODI_TEST)
|
|
115
|
+
|
|
116
|
+
mock.get(test_url, status=429, payload={"message": "Too Many Requests"})
|
|
117
|
+
with pytest.raises(TooManyRequestsError):
|
|
118
|
+
await station_data.get_station_data(STATION_CODI_TEST)
|
|
119
|
+
|
|
120
|
+
mock.get(test_url, status=500, payload={"message": "Internal Server Error"})
|
|
121
|
+
with pytest.raises(InternalServerError):
|
|
122
|
+
await station_data.get_station_data(STATION_CODI_TEST)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
def test_imports():
|
|
2
|
+
from meteocatpy import (
|
|
3
|
+
MeteocatTown,
|
|
4
|
+
MeteocatForecast,
|
|
5
|
+
MeteocatSymbols,
|
|
6
|
+
MeteocatStations,
|
|
7
|
+
MeteocatTownStations,
|
|
8
|
+
MeteocatStationData,
|
|
9
|
+
MeteocatVariables,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
assert MeteocatTown is not None
|
|
13
|
+
assert MeteocatForecast is not None
|
|
14
|
+
assert MeteocatSymbols is not None
|
|
15
|
+
assert MeteocatStations is not None
|
|
16
|
+
assert MeteocatTownStations is not None
|
|
17
|
+
assert MeteocatStationData is not None
|
|
18
|
+
assert MeteocatVariables is not None
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.town import MeteocatTown
|
|
6
|
+
from meteocatpy.forecast import MeteocatForecast
|
|
7
|
+
|
|
8
|
+
# Cargar variables desde el archivo .env
|
|
9
|
+
load_dotenv()
|
|
10
|
+
|
|
11
|
+
# Obtener los valores del archivo .env
|
|
12
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
13
|
+
MUNICIPI_TEST = os.getenv("MUNICIPI_TEST")
|
|
14
|
+
MUNICIPI_CODI_TEST = os.getenv("MUNICIPI_CODI_TEST")
|
|
15
|
+
|
|
16
|
+
# Asegúrate de que las variables estén definidas
|
|
17
|
+
assert API_KEY, "API Key is required"
|
|
18
|
+
assert MUNICIPI_TEST, "Municipi test is required"
|
|
19
|
+
assert MUNICIPI_CODI_TEST, "Municipi codi test is required"
|
|
20
|
+
|
|
21
|
+
@pytest.mark.asyncio
|
|
22
|
+
async def test_municipis():
|
|
23
|
+
# Crear una instancia de MeteocatTown con la API Key
|
|
24
|
+
town_client = MeteocatTown(API_KEY)
|
|
25
|
+
|
|
26
|
+
# Obtener los municipios
|
|
27
|
+
municipios_data = await town_client.get_municipis()
|
|
28
|
+
|
|
29
|
+
# Crear la carpeta si no existe
|
|
30
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
31
|
+
|
|
32
|
+
# Guardar los datos de los municipios en un archivo JSON
|
|
33
|
+
with open('tests/files/municipis.json', 'w', encoding='utf-8') as f:
|
|
34
|
+
json.dump(municipios_data, f, ensure_ascii=False, indent=4)
|
|
35
|
+
|
|
36
|
+
# Verificar que los municipios no estén vacíos
|
|
37
|
+
assert municipios_data, "Municipis data is empty"
|
|
38
|
+
|
|
39
|
+
# Verificar que el municipio de prueba esté en la lista
|
|
40
|
+
municipi_names = [m['nom'] for m in municipios_data]
|
|
41
|
+
assert MUNICIPI_TEST in municipi_names, f"{MUNICIPI_TEST} not found in municipis list"
|
|
42
|
+
|
|
43
|
+
@pytest.mark.asyncio
|
|
44
|
+
async def test_predict_horaria():
|
|
45
|
+
# Crear una instancia de MeteocatForecast con la API Key
|
|
46
|
+
forecast_client = MeteocatForecast(API_KEY)
|
|
47
|
+
|
|
48
|
+
# Obtener la predicción horaria para el municipio de prueba
|
|
49
|
+
prediccion_hora = await forecast_client.get_prediccion_horaria(MUNICIPI_CODI_TEST)
|
|
50
|
+
|
|
51
|
+
# Crear la carpeta si no existe
|
|
52
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
53
|
+
|
|
54
|
+
# Guardar la predicción horaria en un archivo JSON
|
|
55
|
+
with open('tests/files/predict_hora.json', 'w', encoding='utf-8') as f:
|
|
56
|
+
json.dump(prediccion_hora, f, ensure_ascii=False, indent=4)
|
|
57
|
+
|
|
58
|
+
# Verificar que la predicción horaria no esté vacía
|
|
59
|
+
assert prediccion_hora, "Prediccion horaria is empty"
|
|
60
|
+
|
|
61
|
+
@pytest.mark.asyncio
|
|
62
|
+
async def test_predict_diaria():
|
|
63
|
+
# Crear una instancia de MeteocatForecast con la API Key
|
|
64
|
+
forecast_client = MeteocatForecast(API_KEY)
|
|
65
|
+
|
|
66
|
+
# Obtener la predicción diaria para el municipio de prueba
|
|
67
|
+
prediccion_dia = await forecast_client.get_prediccion_diaria(MUNICIPI_CODI_TEST)
|
|
68
|
+
|
|
69
|
+
# Crear la carpeta si no existe
|
|
70
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
71
|
+
|
|
72
|
+
# Guardar la predicción diaria en un archivo JSON
|
|
73
|
+
with open('tests/files/predict_dia.json', 'w', encoding='utf-8') as f:
|
|
74
|
+
json.dump(prediccion_dia, f, ensure_ascii=False, indent=4)
|
|
75
|
+
|
|
76
|
+
# Verificar que la predicción diaria no esté vacía
|
|
77
|
+
assert prediccion_dia, "Prediccion diaria is empty"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.forecast import MeteocatForecast
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
MUNICIPI_TEST = os.getenv("MUNICIPI_TEST")
|
|
13
|
+
MUNICIPI_CODI_TEST = os.getenv("MUNICIPI_CODI_TEST")
|
|
14
|
+
|
|
15
|
+
# Asegúrate de que las variables estén definidas
|
|
16
|
+
assert API_KEY, "API Key is required"
|
|
17
|
+
assert MUNICIPI_TEST, "Municipi test is required"
|
|
18
|
+
assert MUNICIPI_CODI_TEST, "Municipi codi test is required"
|
|
19
|
+
|
|
20
|
+
@pytest.mark.asyncio
|
|
21
|
+
async def test_predict_horaria():
|
|
22
|
+
# Crear una instancia de MeteocatForecast con la API Key
|
|
23
|
+
forecast_client = MeteocatForecast(API_KEY)
|
|
24
|
+
|
|
25
|
+
# Obtener la predicción horaria para el municipio de prueba
|
|
26
|
+
prediccion_hora = await forecast_client.get_prediccion_horaria(MUNICIPI_CODI_TEST)
|
|
27
|
+
|
|
28
|
+
# Crear la carpeta si no existe
|
|
29
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
30
|
+
|
|
31
|
+
# Guardar la predicción horaria en un archivo JSON
|
|
32
|
+
with open('tests/files/predict_hora.json', 'w', encoding='utf-8') as f:
|
|
33
|
+
json.dump(prediccion_hora, f, ensure_ascii=False, indent=4)
|
|
34
|
+
|
|
35
|
+
# Verificar que la predicción horaria no esté vacía
|
|
36
|
+
assert prediccion_hora, "Prediccion horaria is empty"
|
|
37
|
+
|
|
38
|
+
@pytest.mark.asyncio
|
|
39
|
+
async def test_predict_diaria():
|
|
40
|
+
# Crear una instancia de MeteocatForecast con la API Key
|
|
41
|
+
forecast_client = MeteocatForecast(API_KEY)
|
|
42
|
+
|
|
43
|
+
# Obtener la predicción diaria para el municipio de prueba
|
|
44
|
+
prediccion_dia = await forecast_client.get_prediccion_diaria(MUNICIPI_CODI_TEST)
|
|
45
|
+
|
|
46
|
+
# Crear la carpeta si no existe
|
|
47
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
48
|
+
|
|
49
|
+
# Guardar la predicción diaria en un archivo JSON
|
|
50
|
+
with open('tests/files/predict_dia.json', 'w', encoding='utf-8') as f:
|
|
51
|
+
json.dump(prediccion_dia, f, ensure_ascii=False, indent=4)
|
|
52
|
+
|
|
53
|
+
# Verificar que la predicción diaria no esté vacía
|
|
54
|
+
assert prediccion_dia, "Prediccion diaria is empty"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.data import MeteocatStationData
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
STATION_CODI_TEST = os.getenv("STATION_CODI_TEST")
|
|
13
|
+
|
|
14
|
+
# Asegúrate de que las variables estén definidas
|
|
15
|
+
assert API_KEY, "API Key is required"
|
|
16
|
+
assert STATION_CODI_TEST, "Station codi test is required"
|
|
17
|
+
|
|
18
|
+
@pytest.mark.asyncio
|
|
19
|
+
async def test_stations_data():
|
|
20
|
+
# Crear una instancia de MeteocatStationData con la API Key
|
|
21
|
+
data_client = MeteocatStationData(API_KEY)
|
|
22
|
+
|
|
23
|
+
# Obtener los datos de la estación
|
|
24
|
+
station_data = await data_client.get_station_data(STATION_CODI_TEST)
|
|
25
|
+
|
|
26
|
+
# Crear la carpeta si no existe
|
|
27
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
28
|
+
|
|
29
|
+
# Guardar los datos de las estaciones en un archivo JSON
|
|
30
|
+
with open(f'tests/files/station_{STATION_CODI_TEST}_data.json', 'w', encoding='utf-8') as f:
|
|
31
|
+
json.dump(station_data, f, ensure_ascii=False, indent=4)
|
|
32
|
+
|
|
33
|
+
# Verificar que los datos no estén vacíos
|
|
34
|
+
assert station_data, "Estaciones data is empty"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.stations import MeteocatStations
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
|
|
13
|
+
# Asegúrate de que las variables estén definidas
|
|
14
|
+
assert API_KEY, "API Key is required"
|
|
15
|
+
|
|
16
|
+
@pytest.mark.asyncio
|
|
17
|
+
async def test_stations():
|
|
18
|
+
# Crear una instancia de MeteocatStations con la API Key
|
|
19
|
+
stations_client = MeteocatStations(API_KEY)
|
|
20
|
+
|
|
21
|
+
# Obtener las estaciones
|
|
22
|
+
stations_data = await stations_client.get_stations()
|
|
23
|
+
|
|
24
|
+
# Crear la carpeta si no existe
|
|
25
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
26
|
+
|
|
27
|
+
# Guardar los datos de las estaciones en un archivo JSON
|
|
28
|
+
with open('tests/files/stations.json', 'w', encoding='utf-8') as f:
|
|
29
|
+
json.dump(stations_data, f, ensure_ascii=False, indent=4)
|
|
30
|
+
|
|
31
|
+
# Verificar que los municipios no estén vacíos
|
|
32
|
+
assert stations_data, "Estaciones data is empty"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.symbols import MeteocatSymbols
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
|
|
13
|
+
# Asegúrate de que las variables estén definidas
|
|
14
|
+
assert API_KEY, "API Key is required"
|
|
15
|
+
|
|
16
|
+
@pytest.mark.asyncio
|
|
17
|
+
async def test_simbols():
|
|
18
|
+
# Crear una instancia de MeteocatSymbols con la API Key
|
|
19
|
+
symbols_client = MeteocatSymbols(API_KEY)
|
|
20
|
+
|
|
21
|
+
# Obtener los símbolos
|
|
22
|
+
simbolos_data = await symbols_client.fetch_symbols()
|
|
23
|
+
|
|
24
|
+
# Verificar la estructura de los datos obtenidos
|
|
25
|
+
print("Estructura de los datos obtenidos:")
|
|
26
|
+
print(simbolos_data) # Esto te mostrará si realmente es una lista de categorías
|
|
27
|
+
|
|
28
|
+
# Crear la carpeta si no existe
|
|
29
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
30
|
+
|
|
31
|
+
# Guardar el JSON completo original
|
|
32
|
+
with open('tests/files/simbols.json', 'w', encoding='utf-8') as f:
|
|
33
|
+
json.dump(simbolos_data, f, ensure_ascii=False, indent=4)
|
|
34
|
+
|
|
35
|
+
# Verificar que los símbolos no estén vacíos
|
|
36
|
+
assert simbolos_data, "Simbols data is empty"
|
|
37
|
+
|
|
38
|
+
# Iterar sobre las categorías y guardar cada una en su propio archivo
|
|
39
|
+
for category in simbolos_data:
|
|
40
|
+
if "valors" in category: # Asegurarse de que tenga "valors"
|
|
41
|
+
category_name = category['nom'] # Nombre de la categoría (e.g., "cel", "mar", etc.)
|
|
42
|
+
|
|
43
|
+
# Reemplazar los espacios por guiones bajos en el nombre de la categoría
|
|
44
|
+
category_name_safe = category_name.replace(' ', '_')
|
|
45
|
+
|
|
46
|
+
# Nombre del archivo con el prefijo "simbols_"
|
|
47
|
+
category_file_name = f'tests/files/simbols_{category_name_safe}.json'
|
|
48
|
+
|
|
49
|
+
# Guardar la categoría y sus valores en un archivo JSON
|
|
50
|
+
category_data = {
|
|
51
|
+
"nom": category_name,
|
|
52
|
+
"descripcio": category["descripcio"],
|
|
53
|
+
"valors": category["valors"]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
with open(category_file_name, 'w', encoding='utf-8') as f:
|
|
57
|
+
json.dump(category_data, f, ensure_ascii=False, indent=4)
|
|
58
|
+
|
|
59
|
+
# Asegurarse de que se hayan creado los archivos correctamente
|
|
60
|
+
for category in simbolos_data:
|
|
61
|
+
if "valors" in category:
|
|
62
|
+
category_name = category['nom']
|
|
63
|
+
|
|
64
|
+
# Reemplazar los espacios por guiones bajos también al verificar
|
|
65
|
+
category_name_safe = category_name.replace(' ', '_')
|
|
66
|
+
|
|
67
|
+
category_file_name = f'tests/files/simbols_{category_name_safe}.json'
|
|
68
|
+
assert os.path.exists(category_file_name), f"File for category {category_name} was not created"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.town import MeteocatTown
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
|
|
13
|
+
# Asegúrate de que las variables estén definidas
|
|
14
|
+
assert API_KEY, "API Key is required"
|
|
15
|
+
|
|
16
|
+
@pytest.mark.asyncio
|
|
17
|
+
async def test_municipis():
|
|
18
|
+
# Crear una instancia de MeteocatTown con la API Key
|
|
19
|
+
town_client = MeteocatTown(API_KEY)
|
|
20
|
+
|
|
21
|
+
# Obtener los municipios
|
|
22
|
+
municipios_data = await town_client.get_municipis()
|
|
23
|
+
|
|
24
|
+
# Crear la carpeta si no existe
|
|
25
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
26
|
+
|
|
27
|
+
# Guardar los datos de los municipios en un archivo JSON
|
|
28
|
+
with open('tests/files/municipis.json', 'w', encoding='utf-8') as f:
|
|
29
|
+
json.dump(municipios_data, f, ensure_ascii=False, indent=4)
|
|
30
|
+
|
|
31
|
+
# Verificar que los municipios no estén vacíos
|
|
32
|
+
assert municipios_data, "Municipis data is empty"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.townstations import MeteocatTownStations
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
MUNICIPI_CODI_TEST = os.getenv("MUNICIPI_CODI_TEST")
|
|
13
|
+
VARIABLE_CODI_TEST = os.getenv("VARIABLE_CODI_TEST")
|
|
14
|
+
|
|
15
|
+
# Asegúrate de que las variables estén definidas
|
|
16
|
+
assert API_KEY, "API Key is required"
|
|
17
|
+
assert MUNICIPI_CODI_TEST, "Municipi codi test is required"
|
|
18
|
+
assert VARIABLE_CODI_TEST, "Variable codi test is required"
|
|
19
|
+
|
|
20
|
+
@pytest.mark.asyncio
|
|
21
|
+
async def test_town_stations():
|
|
22
|
+
# Crear una instancia de MeteocatTownStations con la API Key
|
|
23
|
+
town_stations_client = MeteocatTownStations(API_KEY)
|
|
24
|
+
|
|
25
|
+
# Obtener la lista de estaciones del municipio usando el código de municipio de prueba y la variable de prueba
|
|
26
|
+
town_stations_data = await town_stations_client.get_town_stations(MUNICIPI_CODI_TEST, VARIABLE_CODI_TEST)
|
|
27
|
+
|
|
28
|
+
# Crear la carpeta si no existe
|
|
29
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
30
|
+
|
|
31
|
+
# Guardar la lista de estaciones del municipio en un archivo JSON
|
|
32
|
+
with open(f'tests/files/stations_{MUNICIPI_CODI_TEST}_{VARIABLE_CODI_TEST}.json', 'w', encoding='utf-8') as f:
|
|
33
|
+
json.dump(town_stations_data, f, ensure_ascii=False, indent=4)
|
|
34
|
+
|
|
35
|
+
# Verificar que la lista de estaciones del municipio no esté vacía
|
|
36
|
+
assert town_stations_data, "Estaciones data is empty"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from meteocatpy.variables import MeteocatVariables
|
|
6
|
+
|
|
7
|
+
# Cargar variables desde el archivo .env
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
# Obtener los valores del archivo .env
|
|
11
|
+
API_KEY = os.getenv("METEOCAT_API_KEY")
|
|
12
|
+
|
|
13
|
+
# Asegúrate de que las variables estén definidas
|
|
14
|
+
assert API_KEY, "API Key is required"
|
|
15
|
+
|
|
16
|
+
@pytest.mark.asyncio
|
|
17
|
+
async def test_variables():
|
|
18
|
+
# Crear una instancia de MeteocatVariables con la API Key
|
|
19
|
+
variables_client = MeteocatVariables(API_KEY)
|
|
20
|
+
|
|
21
|
+
# Obtener las variables
|
|
22
|
+
variables_data = await variables_client.get_variables()
|
|
23
|
+
|
|
24
|
+
# Crear la carpeta si no existe
|
|
25
|
+
os.makedirs('tests/files', exist_ok=True)
|
|
26
|
+
|
|
27
|
+
# Guardar los datos de las variables en un archivo JSON
|
|
28
|
+
with open('tests/files/variables.json', 'w', encoding='utf-8') as f:
|
|
29
|
+
json.dump(variables_data, f, ensure_ascii=False, indent=4)
|
|
30
|
+
|
|
31
|
+
# Verificar que las variables no estén vacías
|
|
32
|
+
assert variables_data, "Variables data is empty"
|