LAL 7.7.0.1-eeff03c
test_cache.py
Go to the documentation of this file.
1# Copyright (C) 2019 Duncan Macleod
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation; either version 2 of the License, or (at your
6# option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11# Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17"""Tests for lal.utils.cache
18
19See utils_cache_verify.py for more tests of the same module
20"""
21
22import os
23import sys
24from pathlib import Path
25
26import pytest
27
28import igwn_segments as segments
29
30from lal import (
31 LIGOTimeGPS,
32 utils as lal_utils,
33)
34
35
36class TestCacheEntry():
37 """Test suite for `lal.utils.CacheEntry`.
38 """
39 CacheEntry = lal_utils.CacheEntry
40
41 @pytest.mark.parametrize(("args", "segs"), (
42 # normal
43 (
44 ("A", "TEST", segments.segment(0, 1), "test.gwf"),
45 {'A': [segments.segment(0, 1)]},
46 ),
47 # empty instruments
48 (
49 ("-", "-", segments.segment(2, 10), "test.gwf"),
50 {None: [segments.segment(2, 10)]},
51 ),
52 # multiple instruments (not sure this is every actually valid)
53 (
54 ("H1,L1", "TEST", segments.segment(5, 10), "test.gwf"),
55 {
56 'H1': [segments.segment(5, 10)],
57 'L1': [segments.segment(5, 10)],
58 },
59 ),
60 ))
61 def test_segmentlistdict(self, args, segs):
62 """Test that `CacheEntry.segmentlistdict` works.
63 """
64 a = self.CacheEntry(*args)
65 assert a.segmentlistdict == segs
66
67 def test_fspath(self):
68 """Test that `CacheEntry` FSPath protocol works.
69 """
70 a = self.CacheEntry("A", "TEST", segments.segment(0, 1), "/path/to/test.gwf")
71 assert str(Path(a)) == a.path
72 assert os.path.basename(a) == "test.gwf"
73
74
76 try:
77 from glue.lal import Cache as GlueCache
78 except ImportError as exc: # no glue installation
79 pytest.skip(str(exc))
80 GlueCache.entry_class = lal_utils.CacheEntry
81
82 files = [
83 "X-TEST-0-1.gwf",
84 "X-TEST-1-1.gwf",
85 ]
86 gcache = GlueCache.from_urls(files, coltype=LIGOTimeGPS)
87 try:
88 lcache = lal_utils.lalcache_from_gluecache(gcache)
89 finally:
90 for fp in files:
91 if os.path.isfile(fp):
92 os.remove(fp)
93 assert lcache.length == len(gcache)
94 assert lcache.list.url == (
95 "file://localhost{}".format(os.path.abspath(files[0]))
96 )
97
98
99if __name__ == '__main__':
100 args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-utils-cache.xml"]
101 sys.exit(pytest.main(args=[__file__] + args))
Test suite for lal.utils.CacheEntry.
Definition: test_cache.py:38
def test_segmentlistdict(self, args, segs)
Test that CacheEntry.segmentlistdict works.
Definition: test_cache.py:63
def test_fspath(self)
Test that CacheEntry FSPath protocol works.
Definition: test_cache.py:69
CacheEntry
Definition: test_cache.py:39
def test_lalcache_from_gluecache()
Definition: test_cache.py:75