Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #24

Draft
wants to merge 43 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
74b639c
BUG: long descritption
aburrell Jul 17, 2020
e6c02e7
ENH: ignore autosaves
aburrell Jul 17, 2020
a301b39
Merge branch 'develop' of https://github.com/SuperDARN/pyDARNio into …
aburrell Sep 18, 2020
ae7e6b8
TST: updated TestSDarnRead
aburrell Sep 18, 2020
b078ec5
TST: updated test_superdarn DarnUtilities
aburrell Sep 21, 2020
676f1d2
BUG: import pyDARNio
aburrell Sep 22, 2020
e6bf7d0
BUG: import pyDARNio
aburrell Sep 22, 2020
143d0f7
BUG: import pyDARNio and whitespace
aburrell Sep 22, 2020
770b979
BUG: test_superdarn pyDARNio imports and unit test bugs
aburrell Sep 22, 2020
864c311
MAINT: remove use of deprecated function
aburrell Sep 23, 2020
0001af3
BUG: updated write_rawacf
aburrell Sep 23, 2020
2b8b7f3
TST: updated test_superdarn
aburrell Sep 23, 2020
a26d732
TST: created general file testing routine
aburrell Sep 24, 2020
987a56d
STY: updated error message
aburrell Sep 24, 2020
6822d35
BUG: incorrect import
aburrell Sep 24, 2020
35de9f5
TST: created test class for pyDARNio file reading
aburrell Sep 24, 2020
ed2c55a
TST: file_utils naming
aburrell Sep 25, 2020
26cc3d7
TST: created common TestWrite class
aburrell Sep 25, 2020
08937cc
BUG: fixed unit test bugs
aburrell Sep 25, 2020
aa6b16f
BUG: pyDARNio import
aburrell Sep 30, 2020
ccf7d1a
TST: updated unit test_conversions
aburrell Sep 30, 2020
3cf1ffd
TST: added TestReadBorealis class
aburrell Oct 1, 2020
d31a18f
STY: list from keys
aburrell Oct 1, 2020
7478307
TST: BorealisWrite class
aburrell Oct 1, 2020
bbd5f14
TST: borealis general classes
aburrell Oct 2, 2020
af3b9de
TST: added missing init files
aburrell Oct 2, 2020
ee71b05
TST: changed testing structure
aburrell Oct 5, 2020
1672dfd
TST: Started new test class TestReadWrite
aburrell Oct 6, 2020
4f4d444
TST: updated file_utils
aburrell Oct 7, 2020
1c4ee7e
TST: partial test_superdarn integration update
aburrell Oct 7, 2020
0a25432
TST: test_superdarn integration update
aburrell Oct 8, 2020
e85a3ca
TST: flake8 update
aburrell Oct 8, 2020
1f2ef51
BUG: integration test bugs
aburrell Oct 8, 2020
9714931
BUG: stream kwarg
aburrell Oct 9, 2020
4fbcdb5
BUG: fixing test failures
aburrell Oct 9, 2020
d265435
TST: uncommented failing test
aburrell Oct 9, 2020
8548dc5
Merge branch 'integration_tests' into update_integration_tests
aburrell Jun 28, 2021
bfb2025
Merge pull request #26 from SuperDARN/update_integration_tests
aburrell Jun 28, 2021
897acc4
BUG: fixed bad import name
aburrell Jun 28, 2021
6dd7e43
BUG: fixed more imports
aburrell Jun 28, 2021
9837046
BUG: fixed pyDARNio imports
aburrell Jun 28, 2021
75f4a5d
MAINT: removed copyright
aburrell Jun 28, 2021
318bb8b
MAINT: removed copyright
aburrell Jun 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.py[cod~]
*$py.class

# C extensions
Expand Down
7 changes: 7 additions & 0 deletions pyDARNio/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
# Full license can be found in License.md
# Author: Angeline G. Burrell, NRL
# ----------------------------------------------------------------------------

# Import testing utilities
from pydarnio.tests import utils
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
rawacf_stream = "../testfiles/20170410.1801.00.sas.stream.rawacf.bz2"
rawacf_file = "../testfiles/20170410.1801.00.sas.rawacf"

pydarnio_logger = logging.getLogger('pydarnio')
pydarnio_logger = logging.getLogger('pyDARNio')


class IntegrationDmap(unittest.TestCase):
Expand Down
280 changes: 280 additions & 0 deletions pyDARNio/tests/integration/test_superdarn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
# Copyright (C) 2019 SuperDARN
# Author: Marina Schmidt, Angeline G. Burrell
# --------------------------------------------

import logging
import numpy as np
import os

import pydarnio
from pydarnio import superdarn_exceptions as sdarn_exc
from pydarnio.tests.utils import file_utils

pydarnio_logger = logging.getLogger('pyDARNio')


class TestSDarnReadWrite(file_utils.TestReadWrite):
def setUp(self):
self.test_dir = os.path.join("..", "testdir")
self.read_class = pydarnio.SDarnRead
self.write_class = pydarnio.SDarnWrite
self.read_func = None
self.write_func = None
self.read_dmap = None
self.written_dmap = None
self.temp_file = "temp.file"
self.read_types = ['rawacf', 'fitacf', 'iqdat', 'grid', 'map']
self.write_types = ['rawacf', 'fitacf', 'iqdat', 'grid', 'map']
self.file_types = []

def tearDown(self):
del self.read_func, self.write_func, self.read_dmap, self.written_dmap
del self.temp_file, self.file_types, self.test_dir, self.read_class
del self.write_class, self.read_types, self.write_types


class TestSDarnReadDmapWrite(file_utils.TestReadWrite):
def setUp(self):
self.test_dir = os.path.join("..", "testdir")
self.read_class = pydarnio.SDarnRead
self.write_class = pydarnio.DmapWrite
self.read_func = None
self.write_func = None
self.read_dmap = None
self.written_dmap = None
self.temp_file = "temp.file"
self.read_types = ['rawacf', 'fitacf', 'iqdat', 'grid', 'map']
self.write_types = ['dmap']
self.file_types = []

def tearDown(self):
del self.read_func, self.write_func, self.read_dmap, self.written_dmap
del self.temp_file, self.file_types, self.test_dir, self.read_class
del self.write_class, self.read_types, self.write_types

def test_write_missing_success_read_error(self):
"""Raise SuperDARNFieldMissingError when reading partially written file
"""

# Set the missing field name and record number
missing_field = {'rawacf': 'nave', 'fitacf': 'nave', 'iqdat': 'nave',
'grid': 'stid', 'map': 'stid'}
rnum = 0
self.set_file_types()

# Test each of the file types
for val in self.file_types:
with self.subTest(val=val):
# Get the locally stored data and delete a neccesary value
(self.read_dmap,
self.temp_file) = file_utils.load_data_w_filename(val[0])
del self.read_dmap[rnum][missing_field[val[0]]]

# Write the partial data
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])
self.write_func(self.temp_file)

# Read in the patial data
self.set_read_func(val[0])

with self.assertRaises(
sdarn_exc.SuperDARNFieldMissingError) as err:
self.written_dmap = self.read_func()

# Test the error message raised
self.assertEqual(err.exception.fields, {missing_field[val[0]]})
self.assertEqual(err.exception.record_number, rnum)

# Remove the the temporary file
self.assertTrue(file_utils.remove_temp_file(self.temp_file))

def test_write_extra_read_error(self):
"""Raise SuperDARNExtraFieldError when reading file written with extra
field
"""
# Set the missing field name and record number
rnum = 0
extra_key = 'dummy'
extra_field = {extra_key: pydarnio.DmapScalar(
name=extra_key, value=extra_key, data_type=9, data_type_fmt='s')}
self.set_file_types()

# Test each of the file types
for val in self.file_types:
with self.subTest(val=val):
# Get the locally stored data and add an extra value
(self.read_dmap,
self.temp_file) = file_utils.load_data_w_filename(val[0])
self.read_dmap[rnum].update(extra_field)
self.read_dmap[rnum].move_to_end(extra_key, last=False)

# Write the extra data
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])
self.write_func(self.temp_file)

# Read in the extra data
self.set_read_func(val[0])

with self.assertRaises(
sdarn_exc.SuperDARNExtraFieldError) as err:
self.written_dmap = self.read_func()

# Test the error message raised
self.assertEqual(err.exception.fields, {extra_key})
self.assertEqual(err.exception.record_number, rnum)

# Remove the the temporary file
self.assertTrue(file_utils.remove_temp_file(self.temp_file))

def test_write_incorrect_read_rawacf_from_dict(self):
"""Raise SuperDARNDataFormatTypeError when reading badly written dict
"""
# Test the only file type that currently has a data dict
self.read_types = ['rawacf_dict']
self.set_file_types()

for val in self.file_types:
with self.subTest(val=val):
# Get the locally stored data and add a bad dictionary record
read_dict, self.temp_file = file_utils.load_data_w_filename(
val[0])
read_dict[0]['stid'] = np.int8(read_dict[0]['stid'])

# Convert from dict to Dmap
self.read_dmap = pydarnio.dict2dmap(read_dict)

# Write the Dmap data
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])
self.write_func(self.temp_file)

# Read from the written file
self.set_read_func(val[0].split('_')[0])
with self.assertRaises(sdarn_exc.SuperDARNDataFormatTypeError):
self.written_dmap = self.read_func()

# Remove the temporary file
self.assertTrue(file_utils.remove_temp_file(self.temp_file))


class TestDmapReadSDarnWrite(file_utils.TestReadWrite):
def setUp(self):
self.test_dir = os.path.join("..", "testdir")
self.read_class = pydarnio.DmapRead
self.write_class = pydarnio.SDarnWrite
self.read_func = None
self.write_func = None
self.read_dmap = None
self.written_dmap = None
self.temp_file = "temp.file"
self.read_types = ['rawacf', 'fitacf', 'iqdat', 'grid', 'map']
self.write_types = ['rawacf', 'fitacf', 'iqdat', 'grid', 'map']
self.file_types = []

def tearDown(self):
del self.read_func, self.write_func, self.read_dmap, self.written_dmap
del self.temp_file, self.file_types, self.test_dir, self.read_class
del self.write_class, self.read_types, self.write_types

def test_dict2dmap_write_rawacf(self):
"""Use dict2dmap to convert a dictionary to DMap then SDarnWrite file
"""
# Test the only file type that currently has a data dict
self.read_types = ['rawacf_dict']
self.write_types = ['rawacf']
self.set_file_types()

for val in self.file_types:
with self.subTest(val=val):
# Get the locally stored data
read_dict, self.temp_file = file_utils.load_data_w_filename(
val[0])

# Convert from dict to Dmap
self.read_dmap = pydarnio.dict2dmap(read_dict)

# Write the Dmap data
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])
self.write_func(self.temp_file)

# Read in the Dmap data
self.set_read_func(val[0].split('_')[0])
self.written_dmap = self.read_func()

# Compare the read and written data
self.dmap_list_compare()

# Remove the temporary file
self.assertTrue(file_utils.remove_temp_file(self.temp_file))

def test_write_incorrect_rawacf_from_dict(self):
"""Raise SuperDARNDataFormatTypeError when writing badly formatted dict
"""
# Test the only file type that currently has a data dict
self.read_types = ['rawacf_dict']
self.write_types = ['rawacf']
self.set_file_types()

for val in self.file_types:
with self.subTest(val=val):
# Get the locally stored data and add a bad dictionary record
read_dict, self.temp_file = file_utils.load_data_w_filename(
val[0])
read_dict[0]['stid'] = np.int8(read_dict[0]['stid'])

# Convert from dict to Dmap
self.read_dmap = pydarnio.dict2dmap(read_dict)

# Write the Dmap data
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])

with self.assertRaises(sdarn_exc.SuperDARNDataFormatTypeError):
self.write_func(self.temp_file)

# There won't be a temporary file
self.assertFalse(file_utils.remove_temp_file(self.temp_file))

def test_DmapRead_SDarnWrite_SDarnRead(self):
"""Test read/write/read with DmapRead, SDarnWrite, and SDarnRead
"""
if not os.path.isdir(self.test_dir):
self.skipTest('test directory is not included with pyDARNio')

test_file_dict = file_utils.get_test_files("good",
test_dir=self.test_dir)
self.set_file_types()

for val in self.file_types:
with self.subTest(val=val):
# Read in the test file
self.temp_file = test_file_dict[val[0]]
self.set_read_func(val[0])
self.read_dmap = self.read_func()

# Write the data
self.temp_file = "{:s}_test.{:s}".format(val[0], val[0])
self.write_func = file_utils.set_write_func(self.write_class,
self.read_dmap,
val[1])
self.write_func(self.temp_file)

# Read in again using SDarnRead
self.read_class = pydarnio.SDarnRead
self.set_read_func(val[0])
self.written_dmap = self.read_func()
self.read_class = pydarnio.DmapRead # Reset the reading class

# Assert the read and written data are the same
self.dmap_list_compare()

# Test the file creation and remove the temp file
self.assertTrue(file_utils.remove_temp_file(self.temp_file))
Empty file added pyDARNio/tests/unit/__init__.py
Empty file.
Loading