Skip to content
Snippets Groups Projects
Commit 75183b0c authored by Robbie Luijben's avatar Robbie Luijben
Browse files

Added a few unit tests for beam and connectors

parent c37285ae
No related branches found
No related tags found
1 merge request!7Improve test coverage
def calc_beam(name):
# the beam number can be found by parsing the number in the string pattern "_B012."
beam = 0
try:
position = name.find("_B")
if position>=0:
beam_string = name[position:position+6]
if beam_string.find(".") == 5:
beam = int(beam_string[2:5])
return beam
except:
pass
return 0
\ No newline at end of file
......@@ -6,6 +6,8 @@ from psycopg2 import Error
import argparse
import sql_scripts
from scripts.beam import calc_beam
def parse_database_url(url):
# parse database url like: postgres:postgres@localhost:5432/altadb_1sept2022
......@@ -26,24 +28,6 @@ def parse_database_url(url):
return user, password, host, database, db_port
def calc_beam(name):
# the beam number can be found by parsing the number in the string pattern "_B012."
beam = 0
try:
position = name.find("_B")
if position>=0:
beam_string = name[position:position+6]
if beam_string.find(".") == 5:
beam = int(beam_string[2:5])
return beam
except:
pass
return 0
# conversion algorithm to extract a bit more metadata from an ALTA record
def convert_dataproduct(row):
name, pid, access_url, ra, dec, dt, dst, observation = row
......
......@@ -6,6 +6,8 @@ from psycopg2 import Error
import argparse
import sql_scripts
from scripts.beam import calc_beam
def parse_database_url(url):
......@@ -27,24 +29,6 @@ def parse_database_url(url):
return user, password, host, database, db_port
def calc_beam(name):
# the beam number can be found by parsing the number in the string pattern "_B012."
beam = 0
try:
position = name.find("_B")
if position>=0:
beam_string = name[position:position+6]
if beam_string.find(".") == 5:
beam = int(beam_string[2:5])
return beam
except:
pass
return 0
# conversion algorithm to extract a bit more metadata from an ALTA record
def convert_dataproduct(row):
name, pid, access_url, ra, dec, dt, dst, observation = row
......
import unittest
from scraper.adex_io import ADEX
class TestConnectors(unittest.TestCase):
def test_connector(self):
pass
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
import unittest
from scripts.beam import calc_beam
class TestBeam(unittest.TestCase):
def test_calc_beam_no_beam_number_at_all(self):
actual = calc_beam("abc")
expected = 0
self.assertEqual(actual, expected)
def test_calc_beam_no_beam_number_but_partial_match_no_dot(self):
actual = calc_beam("_BXXXXX")
expected = 0
self.assertEqual(actual, expected)
def test_calc_beam_valid_beam_number(self):
actual = calc_beam("_B099.")
expected = 99
self.assertEqual(actual, expected)
\ No newline at end of file
import types
import unittest
from scraper.postgres.connectors.apertif import Inspectionplots
class TestConnectorPostgresApertif(unittest.TestCase):
def test_translate(self):
connector = Inspectionplots()
name = 'my_name'
pid = 5
url = 'some_access_url'
dataset_id = 23
row = (name, pid, url, '', '', dataset_id)
args_collection = [1, 2, 3]
args = types.SimpleNamespace(collection=args_collection)
actual = connector.translate(row=row, args=args)
expected = {
'pid': pid,
'name': name,
'dp_type': 'diagnostic_plots',
'format': 'png',
'locality': 'online',
'access_url': url,
'dataset_id': str(dataset_id),
'parent': None,
'collection': args_collection,
}
self.assertDictEqual(actual, expected)
import unittest
# TODO: implement
class TestConnectorVOApertif(unittest.TestCase):
pass
# TODO: implement
class TestConnectorVOFocus(unittest.TestCase):
pass
# TODO: implement
class TestConnectorVOLotssDR2(unittest.TestCase):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment