Skip to content

Commit

Permalink
add test for init
Browse files Browse the repository at this point in the history
  • Loading branch information
FusRoman committed Sep 1, 2022
1 parent 7906379 commit ab2118e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ exclude =
build,
dist
per-file-ignores =
../Fink_GRB/fink_grb/online/ztf_join_gcn.py:W503
../Fink_GRB/fink_grb/online/ztf_join_gcn.py:W503,E402
61 changes: 43 additions & 18 deletions fink_grb/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from importlib.resources import files
import logging

from fink_grb import __name__
import fink_grb


def init_fink_grb(arguments):
Expand All @@ -19,23 +19,15 @@ def init_fink_grb(arguments):
Returns
-------
None
"""
# read the config file
config = configparser.ConfigParser(os.environ)
if arguments["--config"]:
if os.path.exists(arguments["--config"]):
config.read(arguments["--config"])
else: # pragma: no cover
print(
"config file does not exist from this path: {} !!".format(
arguments["--config"]
)
)
exit(1)
else:
config_path = files("fink_grb").joinpath("conf/fink_grb.conf")
config.read(config_path)
Examples
--------
>>> init_fink_grb({"--config" : None})
>>> os.path.isdir("gcn_storage_default/raw")
True
>>> shutil.rmtree("gcn_storage_default")
"""
config = get_config(arguments)

output_path = config["PATH"]["online_gcn_data_prefix"]

Expand All @@ -57,6 +49,20 @@ def get_config(arguments):
-------
config : ConfigParser
the ConfigParser object containing the entry from the config file
Examples
--------
>>> c = get_config({"--config" : "fink_grb/conf/fink_grb.conf"})
>>> type(c)
<class 'configparser.ConfigParser'>
>>> c.sections()
['CLIENT', 'PATH', 'STREAM']
>>> c = get_config({"--config" : None})
>>> type(c)
<class 'configparser.ConfigParser'>
>>> c.sections()
['CLIENT', 'PATH', 'STREAM']
"""
# read the config file
config = configparser.ConfigParser(os.environ)
Expand Down Expand Up @@ -91,9 +97,14 @@ def init_logging():
logger : Logger object
A logger object for the logging management.
Examples
--------
>>> l = init_logging()
>>> type(l)
<class 'logging.Logger'>
"""
# create logger
logger = logging.getLogger(__name__)
logger = logging.getLogger(fink_grb.__name__)
logger.setLevel(logging.DEBUG)

# create console handler and set level to debug
Expand All @@ -112,3 +123,17 @@ def init_logging():
logger.addHandler(ch)

return logger


if __name__ == "__main__": # pragma: no cover
import sys
import doctest
from pandas.testing import assert_frame_equal # noqa: F401
import pandas as pd # noqa: F401
import shutil # noqa: F401

if "unittest.util" in __import__("sys").modules:
# Show full diff in self.assertEqual.
__import__("sys").modules["unittest.util"]._MAX_LENGTH = 999999999

sys.exit(doctest.testmod()[0])
5 changes: 3 additions & 2 deletions fink_grb/online/ztf_join_gcn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import warnings
warnings.filterwarnings("ignore")


import pandas as pd
import numpy as np
import time
Expand All @@ -20,8 +23,6 @@
from fink_grb.init import get_config, init_logging
from fink_broker.science import ang2pix

warnings.filterwarnings("ignore")

def compute_healpix_column(spark_df, ra, dec, nside):
"""
Compute a columns of pixels id and add it to the spark_df dataframe.
Expand Down

0 comments on commit ab2118e

Please sign in to comment.