Commit 6cb5f90b authored by Adam Mercer's avatar Adam Mercer

Merge branch 'lalframe-frutils-tests' into 'master'

Add test suite for lalframe.utils.frtools

See merge request !1111
parents 74303a79 532110c5
Pipeline #92983 passed with stages
in 362 minutes and 7 seconds
# Copyright (C) 2013 Duncan Macleod
# -*- coding: utf-8 -*-
# Copyright (C) 2013,2019 Duncan Macleod
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -15,15 +16,12 @@
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
"""Native python versions of LIGOTools and FrXXX frame utilities utilities
"""Native python versions of LIGOTools and FrXXX frame utilities
"""
import lalframe
from lalframe import git_version
__author__ = "Duncan Macleod <duncan.macleod@ligo.org>"
__version__ = git_version.id
__date__ = git_version.date
def get_channels(framefile):
......@@ -33,7 +31,7 @@ def get_channels(framefile):
@param framefile
`string` path to input frame file
@returns a list of all channels present in the table of contents
@return A list of channel names
Example:
......@@ -42,15 +40,22 @@ def get_channels(framefile):
['H1:LSC-DATA_QUALITY_VECTOR', 'H1:IFO-SV_STATE_VECTOR', 'H1:LDAS-STRAIN']
\endcode
"""
frfile = lalframe.FrameUFrFileOpen(framefile, "r")
return sorted(iter_channels(framefile))
def iter_channels(framefile):
"""Yield channels from the table-of-contents of the given GWF file
@param framefile
`str` path to input frame file
@return An iterator of channel names
"""
frfile = lalframe.FrameUFrFileOpen(str(framefile), "r")
frtoc = lalframe.FrameUFrTOCRead(frfile)
nadc = lalframe.FrameUFrTOCQueryAdcN(frtoc)
nproc = lalframe.FrameUFrTOCQueryProcN(frtoc)
nsim = lalframe.FrameUFrTOCQuerySimN(frtoc)
adcchannels = [lalframe.FrameUFrTOCQueryAdcName(frtoc, i) for
i in range(nadc)]
procchannels = [lalframe.FrameUFrTOCQuerySimName(frtoc, i) for
i in range(nsim)]
simchannels = [lalframe.FrameUFrTOCQueryProcName(frtoc, i) for
i in range(nproc)]
return sorted(adcchannels + procchannels + simchannels)
for i in range(lalframe.FrameUFrTOCQueryAdcN(frtoc)):
yield lalframe.FrameUFrTOCQueryAdcName(frtoc, i)
for i in range(lalframe.FrameUFrTOCQueryProcN(frtoc)):
yield lalframe.FrameUFrTOCQueryProcName(frtoc, i)
for i in range(lalframe.FrameUFrTOCQuerySimN(frtoc)):
yield lalframe.FrameUFrTOCQuerySimName(frtoc, i)
......@@ -6,6 +6,7 @@ test_programs +=
# Add shell, Python, etc. test scripts to this variable
test_scripts += \
test_frread.py \
test_utils_frtools.py \
$(END_OF_LIST)
# Add any helper programs required by tests to this variable
......
......@@ -20,6 +20,7 @@
"""
import sys
import os
try:
from pathlib import Path
except ImportError as exc: # probably macports
......@@ -42,8 +43,11 @@ else:
Cache.entry_class = CacheEntry
# find test GWF file
HERE = Path(__file__).parent.absolute()
TEST_GWF = HERE.parent / "F-TEST-600000060-60.gwf"
TEST_PATH = Path(os.getenv(
"LAL_TEST_SRCDIR",
Path(__file__).parent,
)).absolute().parent
TEST_GWF = TEST_PATH / "F-TEST-600000060-60.gwf"
# parametrize sources
SOURCES = [
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 Duncan Macleod
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Tests for lalframe.utils.frtools
"""
import sys
import os
try:
from pathlib import Path
except ImportError as exc: # probably macports
import warnings
warnings.warn(str(exc))
sys.exit(77)
import pytest
from lalframe import utils
# find test GWF file
TEST_PATH = Path(os.getenv(
"LAL_TEST_SRCDIR",
Path(__file__).parent,
)).absolute().parent
TEST_GWF = TEST_PATH / "F-TEST-600000060-60.gwf"
# test result
TEST_CHANNELS = [
"H1:LSC-AS_Q",
]
def test_get_channels():
assert utils.get_channels(TEST_GWF) == TEST_CHANNELS
if __name__ == '__main__':
if "-v" not in " ".join(sys.argv[1:]): # default to verbose
sys.argv.append("-v")
sys.exit(pytest.main(args=[__file__] + sys.argv[1:]))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment