From 4d2ccba55a762e8c57fd3105fa6d31937fff43d6 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 28 Jul 2025 12:59:58 +0200 Subject: [PATCH] Add basic tests and enable CI --- .github/workflows/python-package.yml | 3 +++ tests/test_indicador.py | 31 ++++++++++++++++++++++++++++ yahoofinance.py | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/test_indicador.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fd71643..9b24a0a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -35,3 +35,6 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Run tests + run: | + python -m pytest -q diff --git a/tests/test_indicador.py b/tests/test_indicador.py new file mode 100644 index 0000000..4ba8e86 --- /dev/null +++ b/tests/test_indicador.py @@ -0,0 +1,31 @@ +import math +from indicador import fibonacci, puntocurvaexponencial, curvexprent, MME + + +def test_fibonacci_basic(): + assert fibonacci(8) == [1, 1, 2, 3, 5, 8, 13] + + +def test_puntocurvaexponencial_example(): + res = puntocurvaexponencial( + '2008-01-25', 48.260, '2008-04-18', 76.958, 'w', fechahoy='2008-05-02' + ) + assert math.isclose(res, 83.182, rel_tol=1e-3) + + +def test_curvexprent_basic(): + res = curvexprent('2010-01-01', 10.0, '2011-01-01', 11.0) + assert math.isclose(res, 0.1, rel_tol=1e-3) + + +def test_mme_length_and_values(): + datos = [ + ('2020-01-01', 1, 1, 1, 1, 1), + ('2020-01-02', 2, 2, 2, 2, 2), + ('2020-01-03', 3, 3, 3, 3, 3), + ('2020-01-04', 4, 4, 4, 4, 4), + ] + res = MME(datos, MME=3) + assert len(res) == len(datos) + assert res[0][1] == 1 + assert math.isclose(res[-1][1], 3.125, rel_tol=1e-3) diff --git a/yahoofinance.py b/yahoofinance.py index 8892aa0..d3355e3 100644 --- a/yahoofinance.py +++ b/yahoofinance.py @@ -575,7 +575,7 @@ def descargaHistoricoAccion2(naccion, **config): o que la url no es valida 'URL invalida' """ - global _cookie, webheaders #, _crumb + naccion = naccion.upper() fechaini = config.get('fechaini', None)