Skip to content

Commit

Permalink
move tree removal out of teardown_method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhosk committed Aug 29, 2023
1 parent 54500ab commit 8d7f773
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
61 changes: 36 additions & 25 deletions tests/unit/test_dio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from astrohack.panel import panel
from astrohack import holog

import astrohack

import pytest
import numpy as np
import shutil
Expand All @@ -20,35 +22,39 @@ class TestAstrohackDio():

@classmethod
def setup_class(cls):
gdown_data('ea25_cal_small_after_fixed.split.ms', download_folder=cls.datafolder)

extract_pointing(ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
parallel=True,
overwrite=True)
astrohack.gdown_utils.download(file="ea25_cal_small_after_fixed.split.ms", folder=cls.datafolder, unpack=True)

extract_pointing(
ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
parallel=True,
overwrite=True
)

cls.holog_mds = extract_holog(ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
data_column='CORRECTED_DATA',
parallel=True,
overwrite=True)

cell_size = np.array([-0.0006442, 0.0006442]) # arcseconds
grid_size = np.array([31, 31]) # pixels
cls.holog_mds = extract_holog(
ms_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.ms',
point_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr',
data_column='CORRECTED_DATA',
parallel=True,
overwrite=True
)

cls.image_mds = holog(holog_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.holog.zarr',
overwrite=True,
phase_fit=True,
apply_mask=True,
to_stokes=True,
parallel=True)
panel_model = 'rigid'
cls.image_mds = holog(
holog_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.holog.zarr',
overwrite=True,
phase_fit=True,
apply_mask=True,
to_stokes=True,
parallel=True
)

cls.panel_mds = panel(image_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.image.zarr',
panel_model=panel_model,
parallel=True,
overwrite=True)
cls.panel_mds = panel(
image_name=cls.datafolder + '/ea25_cal_small_after_fixed.split.image.zarr',
panel_model='rigid',
parallel=True,
overwrite=True
)

@classmethod
def teardown_class(cls):
Expand All @@ -57,23 +63,28 @@ def teardown_class(cls):
def test_open_holog(self):
'''Open a holog file and return a holog data object'''
holog_data = open_holog(self.datafolder + '/ea25_cal_small_after_fixed.split.holog.zarr')

assert holog_data == self.holog_mds

def test_open_image(self):
'''Open an image file and return an image data object'''
image_data = open_image(self.datafolder + '/ea25_cal_small_after_fixed.split.image.zarr')

assert image_data == self.image_mds

def test_open_panel(self):
'''Open a panel file and return a panel data object'''
panel_data = open_panel(self.datafolder + '/ea25_cal_small_after_fixed.split.panel.zarr')

assert panel_data == self.panel_mds

def test_open_pointing(self):
'''Open a pointing file and return a pointing data object'''
pointing_data = open_pointing(self.datafolder + '/ea25_cal_small_after_fixed.split.point.zarr')
# check if keys match expected?
# How to check xarray content...

expected_keys = ['point_meta_ds', 'ant_ea25', 'ant_ea04', 'ant_ea06']

for key in pointing_data.keys():
assert key in expected_keys
10 changes: 5 additions & 5 deletions tests/unit/test_extract_holog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
from astrohack.extract_pointing import extract_pointing
from astrohack.extract_holog import generate_holog_obs_dict

class TestAstrohack():
class TestExtractHolog():
@classmethod
def setup_class(cls):
""" setup any state specific to the execution of the given test class
such as fetching test data """
pass
astrohack.gdown_utils.download(file="ea25_cal_small_after_fixed.split.ms", folder="data/", unpack=True)

@classmethod
def teardown_class(cls):
""" teardown any state that was previously setup with a call to setup_class
such as deleting test data """
pass
shutil.rmtree("data")

def setup_method(self):
""" setup any state specific to all methods of the given class """

astrohack.gdown_utils.download(file="ea25_cal_small_after_fixed.split.ms", folder="data/", unpack=True)
pass

def teardown_method(self):
""" teardown any state that was previously setup for all methods of the given class """
shutil.rmtree("data")
pass

def test_extract_holog_obs_dict(self):

Expand Down
11 changes: 9 additions & 2 deletions tests/unit/test_extract_pointing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import shutil
import pytest
from astrohack.gdown_utils import gdown_data
import astrohack

from astrohack.extract_pointing import extract_pointing


Expand All @@ -11,7 +12,9 @@ def setup_class(cls):
"""setup any state specific to the execution of the given test class"""
cls.datafolder = "point_data"
cls.ms = "ea25_cal_small_after_fixed.split.ms"
gdown_data(cls.ms, download_folder=cls.datafolder)

astrohack.gdown_utils.download(file=cls.ms, folder=cls.datafolder, unpack=True)

cls.ms_name = os.path.join(cls.datafolder, cls.ms)

@classmethod
Expand All @@ -33,13 +36,15 @@ def test_extract_pointing_default(self):

# Check the keys of the returned dictionary
expected_keys = ["point_meta_ds", "ant_ea04", "ant_ea06", "ant_ea25"]

for key in point_obj.keys():
assert key in expected_keys

def test_extract_pointing_point_name(self):
"""Test extract_pointing and save to given point name"""
point_name = os.path.join(self.datafolder, "test_user_point_name.zarr")
point_obj = extract_pointing(ms_name=self.ms_name, point_name=point_name)

assert os.path.exists(point_name)

# Check that the returned dictionary contains the given point_name
Expand All @@ -53,10 +58,12 @@ def test_extract_pointing_overwrite_true(self):

extract_pointing(ms_name=self.ms_name, point_name=point_name, overwrite=True)
modified_time = os.path.getctime(point_name)

assert initial_time != modified_time

def test_extract_pointing_invalid_ms_name(self):
"""Test extract_pointing and check that invalid_ms does not create point file"""
# Exceptions are not raised by the code, therefore doing a silly check here
extract_pointing(ms_name="invalid_name.ms")

assert os.path.exists("invalid_name.point.zarr") is False
2 changes: 1 addition & 1 deletion tests/unit/test_holog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def relative_difference(result, expected):
return 2*np.abs(result - expected)/(abs(result) + abs(expected))

class TestAstrohack():
class TestHolog():
@classmethod
def setup_class(cls):
""" setup any state specific to the execution of the given test class
Expand Down

0 comments on commit 8d7f773

Please sign in to comment.