diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed47a6a..cf137d6 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_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} steps: - name: Checkout code @@ -98,14 +99,20 @@ jobs: ${{ runner.os }}-pip- - name: Install dependencies + env: + FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} run: | python -m pip install --upgrade pip wheel pip install -r requirements.txt pip install -r dev_requirements.txt pip install codecov pytest-cov + python tests/setup_tendrils.py - - name: Coverage testing - continue-on-error: true + - name: Testing + env: + FLOWS_CONFIG: ${{ secrets.FLOWS_CONFIG }} + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} run: pytest --cov - name: Upload coverage @@ -155,10 +162,14 @@ jobs: ${{ runner.os }}-pip- - name: Install dependencies + env: + FLOWS_API_TOKEN: ${{ secrets.FLOWS_API_TOKEN }} + 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();" 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 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/conftest.py b/tests/conftest.py index 2dea176..ac40a63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -61,11 +61,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" diff --git a/tests/setup_tendrils.py b/tests/setup_tendrils.py new file mode 100644 index 0000000..601996a --- /dev/null +++ b/tests/setup_tendrils.py @@ -0,0 +1,20 @@ +from tendrils import utils +import os + + +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 + + 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__': + set_up_tendrils_in_ci() 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) 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__])