diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f9d272951893d59b5696f35a6a94f17790b330c0..c7e2878665e06bbdff96e062bb14f0303873d926 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -153,7 +153,9 @@ Python Lint: Python Test: artifacts: reports: - cobertura: coverage.xml + coverage_report: + coverage_format: cobertura + path: coverage.xml junit: junit.xml needs: - Poetry diff --git a/geomagio/Controller.py b/geomagio/Controller.py index d05f45ae4e8d4848da8e062adddb8540f839e3ef..aa71797462eaad81804de46f5722ab2bad01f8e9 100644 --- a/geomagio/Controller.py +++ b/geomagio/Controller.py @@ -1,7 +1,7 @@ """Controller class for geomag algorithms""" import argparse -from io import BytesIO +from io import StringIO import sys from typing import List, Optional, Tuple, Union @@ -506,7 +506,7 @@ def get_input_factory(args): input_factory_args["urlInterval"] = args.input_url_interval input_factory_args["urlTemplate"] = args.input_url else: - input_stream = BytesIO(Util.read_url(args.input_url)) + input_stream = StringIO(Util.read_url(args.input_url)) input_type = args.input if input_type == "edge": input_factory = edge.EdgeFactory( diff --git a/test/Controller_test.py b/test/Controller_test.py index 4a722adaa053afcff76db7f56fcdf85a0dbd3035..2e51338a6fe316f0ccf4a8dbd146c5a1dc3f5e27 100644 --- a/test/Controller_test.py +++ b/test/Controller_test.py @@ -33,6 +33,85 @@ def test_controller(): assert_equal(isinstance(controller._algorithm, Algorithm), True) +def test_controller_input_url(): + """Controller_test.test_controller_input_url() + + Test `--input-url` option in controller with both a URL template, and + and a simple, single file url. The latter was especially problematic after + switching to Py3 because BytesIO choked on data read in as a string. + NOTE: the bug this was designed to catch was TypeError, so a "pass" is + simply to read in the data file. There is no need to compare it + with anything. + """ + # define folder for testing + tmp_dir = gettempdir() + + # TEST 1 - read in interval using the --input-url option set to a + # URL template (i.e., it has a '{' in the string) + + # create list of string command line arguments + fake_argv = [ + "--input", + "iaga2002", + "--input-url", + "file://etc/controller/{obs}{date:%Y%m%d}_XYZF_{t}{i}.{i}", + "--observatory", + "BOU", + "--inchannels", + "X", + "Y", + "Z", + "F", + "--interval", + "minute", + "--type", + "variation", + "--output", + "iaga2002", + "--output-url", + "file://" + tmp_dir + "/{obs}{date:%Y%m%d}_XYZF_{t}{i}.{i}", + ] + + # parse arguments and create initial args object + args = parse_args(fake_argv) + + starttime1 = args.starttime = UTCDateTime("2018-10-24T00:00:00Z") + endtime1 = args.endtime = UTCDateTime("2018-10-24T00:19:00Z") + _main(args) + + # TEST 2 - read in interval using the --input-url option with no + # URL template (i.e., no '{' in the string, just a single filename) + # create list of string command line arguments + fake_argv = [ + "--input", + "iaga2002", + "--input-url", + "file://etc/controller/bou20181024_XYZF_vmin.min", + "--observatory", + "BOU", + "--inchannels", + "X", + "Y", + "Z", + "F", + "--interval", + "minute", + "--type", + "variation", + "--output", + "iaga2002", + "--output-url", + "file://" + tmp_dir + "/bou20181024_XYZF_noURL_vmin.min", + ] + + # parse arguments and create initial args object + args = parse_args(fake_argv) + + starttime1 = args.starttime = UTCDateTime("2018-10-24T00:00:00Z") + endtime1 = args.endtime = UTCDateTime("2018-10-24T00:19:00Z") + _main(args) + + def test_controller_update_sqdist(): """Controller_test.test_controller_update_sqdist().