From 62a8c268caecb20f2f139f3dc3d24728a2205edb Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 19:52:08 +0200 Subject: [PATCH 01/14] fix test config being broken.. --- tests/conftest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2dea176..9b9206b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,7 @@ import configparser import subprocess import shlex +from tendrils import utils if sys.path[0] != os.path.abspath(os.path.join(os.path.dirname(__file__), '..')): sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) @@ -61,11 +62,17 @@ def SETUP_CONFIG(): with open(config_file, 'w') as fid: config.write(fid) fid.flush() - yield config_file os.remove(config_file) +@pytest.fixture(scope='session', autouse=True) +def config(SETUP_CONFIG): + from tendrils import utils + utils.copy_from_other_config(SETUP_CONFIG) + yield utils.load_config() + + def pytest_addoption(parser): parser.addoption( "--runslow", action="store_true", default=False, help="run slow tests" From 781e5e27c57729e77088421cbbad09043d9768bf Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 19:54:42 +0200 Subject: [PATCH 02/14] Remove wrong continue on error --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed47a6a..2439b37 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -104,8 +104,7 @@ jobs: pip install -r dev_requirements.txt pip install codecov pytest-cov - - name: Coverage testing - continue-on-error: true + - name: Testing run: pytest --cov - name: Upload coverage From b55dc38a7ee6002701706dd06d5bb72664d5ec99 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 22:46:45 +0200 Subject: [PATCH 03/14] add bandaid tendrils setup to CI --- .github/workflows/tests.yml | 1 + tests/conftest.py | 1 - tests/setup_tendrils.py | 12 ++++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/setup_tendrils.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2439b37..365dfca 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -103,6 +103,7 @@ jobs: pip install -r requirements.txt pip install -r dev_requirements.txt pip install codecov pytest-cov + python -m tests/setup_tendrils.py - name: Testing run: pytest --cov diff --git a/tests/conftest.py b/tests/conftest.py index 9b9206b..d0ec49b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,7 +12,6 @@ import configparser import subprocess import shlex -from tendrils import utils if sys.path[0] != os.path.abspath(os.path.join(os.path.dirname(__file__), '..')): sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py new file mode 100644 index 0000000..6528fff --- /dev/null +++ b/tests/setup_tendrils.py @@ -0,0 +1,12 @@ +from tendrils import utils +import os + + +def set_up_tendrils_in_ci(): + # Set UP API key + os.environ.get('FLOWS_API_TOKEN') + utils.set_api_token(token=os.environ.get('FLOWS_API_TOKEN'), overwrite=True) + + +if __name__ == '__main__': + set_up_tendrils_in_ci() From ffe9143f5ef62641e3d1f4c805c2866ea367619a Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 23:06:51 +0200 Subject: [PATCH 04/14] fix tendrils setup --- .github/workflows/tests.yml | 2 +- tests/setup_tendrils.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 365dfca..b4dc0f0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -103,7 +103,7 @@ jobs: pip install -r requirements.txt pip install -r dev_requirements.txt pip install codecov pytest-cov - python -m tests/setup_tendrils.py + python -m tests/setup_tendrils - name: Testing run: pytest --cov diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py index 6528fff..6fd4459 100644 --- a/tests/setup_tendrils.py +++ b/tests/setup_tendrils.py @@ -4,6 +4,12 @@ def set_up_tendrils_in_ci(): # Set UP API key + config = utils.load_config() + if config.has_option('api', 'token'): + token = config.get('api', 'token') + if token not in [None, '', 'None', 'test']: # if not, we probably have a token. + return + os.environ.get('FLOWS_API_TOKEN') utils.set_api_token(token=os.environ.get('FLOWS_API_TOKEN'), overwrite=True) From 15f28c67be064ae989d4be9565dc6e0f74e51339 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 23:11:06 +0200 Subject: [PATCH 05/14] CI fix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b4dc0f0..383ae6f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -103,7 +103,7 @@ jobs: pip install -r requirements.txt pip install -r dev_requirements.txt pip install codecov pytest-cov - python -m tests/setup_tendrils + python tests/setup_tendrils.py - name: Testing run: pytest --cov From bf17396caf610a54f9564af9fe9bdf82ce2dcb84 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 23:40:29 +0200 Subject: [PATCH 06/14] stricter api token check --- tests/setup_tendrils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py index 6fd4459..601996a 100644 --- a/tests/setup_tendrils.py +++ b/tests/setup_tendrils.py @@ -10,8 +10,10 @@ def set_up_tendrils_in_ci(): if token not in [None, '', 'None', 'test']: # if not, we probably have a token. return - os.environ.get('FLOWS_API_TOKEN') - utils.set_api_token(token=os.environ.get('FLOWS_API_TOKEN'), overwrite=True) + token = os.environ.get('FLOWS_API_TOKEN') + if token is None: + raise RuntimeError("API token can not be set up.") + utils.set_api_token(token=token, overwrite=True) if __name__ == '__main__': From 2814a6e8908141a219477b8bcf546791ceb46f4a Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Tue, 28 Jun 2022 23:45:07 +0200 Subject: [PATCH 07/14] add org secrets to tests --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 383ae6f..0b0242e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -63,6 +63,7 @@ jobs: OS: ${{ matrix.os }} PYTHON: ${{ matrix.python-version }} FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} + FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} steps: - name: Checkout code @@ -155,10 +156,14 @@ jobs: ${{ runner.os }}-pip- - name: Install dependencies + env: + FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} + FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} run: | python -m pip install --upgrade pip wheel pip install -r requirements.txt pip install -r dev_requirements.txt + python tests/setup_tendrils.py - name: Update VERSION file run: python -c "from flows import version; version.update_release_version();" From 7842447ded612f63cb5887e46ac27c6e4a598ec1 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 00:16:56 +0200 Subject: [PATCH 08/14] fix for env secret not being picked up by test --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b0242e..e1e4d02 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -99,6 +99,9 @@ jobs: ${{ runner.os }}-pip- - name: Install dependencies + env: + FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} + FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} run: | python -m pip install --upgrade pip wheel pip install -r requirements.txt @@ -107,6 +110,9 @@ jobs: python tests/setup_tendrils.py - name: Testing + env: + FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} + FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} run: pytest --cov - name: Upload coverage From b44c61734a4c6a378e6978a68508fe2eb8b37cdf Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 00:32:29 +0200 Subject: [PATCH 09/14] fix typo in secret --- tests/setup_tendrils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py index 601996a..6a01df0 100644 --- a/tests/setup_tendrils.py +++ b/tests/setup_tendrils.py @@ -10,7 +10,7 @@ def set_up_tendrils_in_ci(): if token not in [None, '', 'None', 'test']: # if not, we probably have a token. return - token = os.environ.get('FLOWS_API_TOKEN') + token = os.environ.get('FLOWS_API_KEY') if token is None: raise RuntimeError("API token can not be set up.") utils.set_api_token(token=token, overwrite=True) From c58ab571841a32936b1af5b370dec764bcfa51ea Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 00:34:26 +0200 Subject: [PATCH 10/14] fix the correct typo in secret --- .github/workflows/tests.yml | 8 ++++---- tests/setup_tendrils.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1e4d02..cf137d6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -63,7 +63,7 @@ jobs: OS: ${{ matrix.os }} PYTHON: ${{ matrix.python-version }} FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} - FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} steps: - name: Checkout code @@ -101,7 +101,7 @@ jobs: - name: Install dependencies env: FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} - FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} run: | python -m pip install --upgrade pip wheel pip install -r requirements.txt @@ -112,7 +112,7 @@ jobs: - name: Testing env: FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} - FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} run: pytest --cov - name: Upload coverage @@ -163,7 +163,7 @@ jobs: - name: Install dependencies env: - FLOWS_API_KEY: ${{ secrets.FLOWS_API_KEY }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} run: | python -m pip install --upgrade pip wheel diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py index 6a01df0..601996a 100644 --- a/tests/setup_tendrils.py +++ b/tests/setup_tendrils.py @@ -10,7 +10,7 @@ def set_up_tendrils_in_ci(): if token not in [None, '', 'None', 'test']: # if not, we probably have a token. return - token = os.environ.get('FLOWS_API_KEY') + token = os.environ.get('FLOWS_API_TOKEN') if token is None: raise RuntimeError("API token can not be set up.") utils.set_api_token(token=token, overwrite=True) From f511db9d63610a31cc8ffc4c35c8dd7d8a07699a Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 00:42:44 +0200 Subject: [PATCH 11/14] remote faulty fixture --- tests/conftest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d0ec49b..ac40a63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -65,11 +65,11 @@ def SETUP_CONFIG(): os.remove(config_file) -@pytest.fixture(scope='session', autouse=True) -def config(SETUP_CONFIG): - from tendrils import utils - utils.copy_from_other_config(SETUP_CONFIG) - yield utils.load_config() +# @pytest.fixture(scope='session', autouse=True) +# def config(SETUP_CONFIG): +# from tendrils import utils +# utils.copy_from_other_config(SETUP_CONFIG) +# yield utils.load_config() def pytest_addoption(parser): From 142cf61343b41f7515bb4a095167913307be5da4 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 00:51:35 +0200 Subject: [PATCH 12/14] remove old tns test setup --- tests/test_tns.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/test_tns.py b/tests/test_tns.py index 82c8d62..ae9f156 100644 --- a/tests/test_tns.py +++ b/tests/test_tns.py @@ -10,14 +10,13 @@ import os import datetime from astropy.coordinates import SkyCoord -from conftest import capture_cli from flows import tns # -------------------------------------------------------------------------------------------------- @pytest.mark.skipif(os.environ.get('CI') == 'true', reason="Disabled on GitHub Actions to avoid too many requests HTTP error") -def test_tns_search(SETUP_CONFIG): +def test_tns_search(): coo_centre = SkyCoord(ra=191.283890127, dec=-0.45909033652, unit='deg', frame='icrs') res = tns.tns_search(coo_centre) @@ -29,7 +28,7 @@ def test_tns_search(SETUP_CONFIG): # -------------------------------------------------------------------------------------------------- @pytest.mark.skipif(os.environ.get('CI') == 'true', reason="Disabled on GitHub Actions to avoid too many requests HTTP error") -def test_tns_get_obj(SETUP_CONFIG): +def test_tns_get_obj(): res = tns.tns_get_obj('2019yvr') print(res) @@ -40,7 +39,7 @@ def test_tns_get_obj(SETUP_CONFIG): # -------------------------------------------------------------------------------------------------- @pytest.mark.skipif(os.environ.get('CI') == 'true', reason="Disabled on GitHub Actions to avoid too many requests HTTP error") -def test_tns_get_obj_noexist(SETUP_CONFIG): +def test_tns_get_obj_noexist(): res = tns.tns_get_obj('1892doesnotexist') print(res) assert res is None @@ -52,7 +51,7 @@ def test_tns_get_obj_noexist(SETUP_CONFIG): @pytest.mark.parametrize('date_begin,date_end', [('2019-01-01', '2019-02-01'), (datetime.date(2019, 1, 1), datetime.date(2019, 2, 1)), (datetime.datetime(2019, 1, 1, 12, 0), datetime.datetime(2019, 2, 1, 12, 0))]) -def test_tns_getnames(SETUP_CONFIG, date_begin, date_end): +def test_tns_getnames(date_begin, date_end): names = tns.tns_getnames(date_begin=date_begin, date_end=date_end, zmin=0, zmax=0.105, objtype=3) print(names) @@ -64,21 +63,21 @@ def test_tns_getnames(SETUP_CONFIG, date_begin, date_end): # -------------------------------------------------------------------------------------------------- -def test_tns_getnames_wronginput(SETUP_CONFIG): +def test_tns_getnames_wronginput(): # Wrong dates should result in ValueError: with pytest.raises(ValueError): tns.tns_getnames(date_begin=datetime.date(2019, 1, 1), date_end=datetime.date(2017, 1, 1)) -# -------------------------------------------------------------------------------------------------- -@pytest.mark.skipif(os.environ.get('CI') == 'true', - reason="Disabled on GitHub Actions to avoid too many requests HTTP error") -def test_run_querytns(SETUP_CONFIG): - # Run the command line interface: - out, err, exitcode = capture_cli('run_querytns.py') - assert exitcode == 0 - - -# -------------------------------------------------------------------------------------------------- -if __name__ == '__main__': - pytest.main([__file__]) +# # -------------------------------------------------------------------------------------------------- +# @pytest.mark.skipif(os.environ.get('CI') == 'true', +# reason="Disabled on GitHub Actions to avoid too many requests HTTP error") +# def test_run_querytns(): +# # Run the command line interface: +# out, err, exitcode = capture_cli('run_querytns.py') +# assert exitcode == 0 +# +# +# # -------------------------------------------------------------------------------------------------- +# if __name__ == '__main__': +# pytest.main([__file__]) From eafd6d0e976cfafbc03e23cec757d90588b105fe Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 01:16:37 +0200 Subject: [PATCH 13/14] fix fileIO test for CI --- flows/fileio.py | 1 - tests/test_fileIO.py | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/flows/fileio.py b/flows/fileio.py index e6ed951..1c37a64 100644 --- a/flows/fileio.py +++ b/flows/fileio.py @@ -50,7 +50,6 @@ class Directories: def __init__(self, config: Optional[ConfigParser] = None): self.config = config or utils.load_config() - def set_output_dirs(self, target_name: str, fileid: int, create: bool = True, output_folder_root: Optional[str] = None) -> None: """ diff --git a/tests/test_fileIO.py b/tests/test_fileIO.py index 6e7d2a8..523e11c 100644 --- a/tests/test_fileIO.py +++ b/tests/test_fileIO.py @@ -1,8 +1,10 @@ -import pytest +import pytest # noqa: F401 import os from flows.fileio import DirectoriesDuringTest, Directories, IOManager from flows.target import Target from tendrils import utils +import conftest # noqa: F401 +import configparser def delete_directories(directories): @@ -11,6 +13,7 @@ def delete_directories(directories): if os.path.exists(directories.output_folder): os.rmdir(directories.output_folder) + def test_import_fileio(): assert True @@ -24,8 +27,12 @@ def test_DirectoriesDuringTest(): delete_directories(tdir) -def test_Directories(): - config = utils.load_config() +def test_Directories(SETUP_CONFIG): + try: + config = utils.load_config(SETUP_CONFIG) + except FileNotFoundError: + config = configparser.ConfigParser() + config['photometry'] = {'archive_local': os.path.abspath(os.path.dirname(__file__))} directories = Directories(config) output_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'output/') directories.set_output_dirs('test', 0, output_folder_root=output_dir) From c1099eaa7e65efda1bd310277354b5bb83304335 Mon Sep 17 00:00:00 2001 From: Emir Karamehmetoglu Date: Wed, 29 Jun 2022 01:30:56 +0200 Subject: [PATCH 14/14] bump version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ff64bb4..d21f8ae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -master-v0.10.6 \ No newline at end of file +master-v0.10.7 \ No newline at end of file