Skip to content

Commit

Permalink
Merge pull request #94 from SNflows/devel
Browse files Browse the repository at this point in the history
Fix tests on CI
  • Loading branch information
emirkmo authored Jun 29, 2022
2 parents 3d942dd + c1099ea commit 8684469
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master-v0.10.6
master-v0.10.7
1 change: 0 additions & 1 deletion flows/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions tests/setup_tendrils.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 10 additions & 3 deletions tests/test_fileIO.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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

Expand All @@ -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)
Expand Down
35 changes: 17 additions & 18 deletions tests/test_tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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__])

0 comments on commit 8684469

Please sign in to comment.