LAL  7.5.0.1-b72065a
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 
19 See utils_cache_verify.py for more tests of the same module
20 """
21 
22 import os
23 import sys
24 
25 import pytest
26 
27 from ligo import segments
28 
29 from lal import (
30  LIGOTimeGPS,
31  utils as lal_utils,
32 )
33 
34 
35 class TestCacheEntry():
36  """Test suite for `lal.utils.CacheEntry`.
37  """
38  CacheEntry = lal_utils.CacheEntry
39 
40  @pytest.mark.parametrize(("args", "segs"), (
41  # normal
42  (
43  ("A", "TEST", segments.segment(0, 1), "test.gwf"),
44  {'A': [segments.segment(0, 1)]},
45  ),
46  # empty instruments
47  (
48  ("-", "-", segments.segment(2, 10), "test.gwf"),
49  {None: [segments.segment(2, 10)]},
50  ),
51  # multiple instruments (not sure this is every actually valid)
52  (
53  ("H1,L1", "TEST", segments.segment(5, 10), "test.gwf"),
54  {
55  'H1': [segments.segment(5, 10)],
56  'L1': [segments.segment(5, 10)],
57  },
58  ),
59  ))
60  def test_segmentlistdict(self, args, segs):
61  """Test that `CacheEntry.segmentlistdict` works.
62  """
63  a = self.CacheEntryCacheEntry(*args)
64  assert a.segmentlistdict == segs
65 
66 
68  try:
69  from glue.lal import Cache as GlueCache
70  except ImportError as exc: # no glue installation
71  pytest.skip(str(exc))
72  GlueCache.entry_class = lal_utils.CacheEntry
73 
74  files = [
75  "X-TEST-0-1.gwf",
76  "X-TEST-1-1.gwf",
77  ]
78  gcache = GlueCache.from_urls(files, coltype=LIGOTimeGPS)
79  try:
80  lcache = lal_utils.lalcache_from_gluecache(gcache)
81  finally:
82  for fp in files:
83  if os.path.isfile(fp):
84  os.remove(fp)
85  assert lcache.length == len(gcache)
86  assert lcache.list.url == (
87  "file://localhost{}".format(os.path.abspath(files[0]))
88  )
89 
90 
91 if __name__ == '__main__':
92  args = sys.argv[1:] or ["-v", "-rs", "--junit-xml=junit-utils-cache.xml"]
93  sys.exit(pytest.main(args=[__file__] + args))
Test suite for lal.utils.CacheEntry.
Definition: test_cache.py:37
def test_segmentlistdict(self, args, segs)
Test that CacheEntry.segmentlistdict works.
Definition: test_cache.py:62
CacheEntry
Definition: test_cache.py:38
def test_lalcache_from_gluecache()
Definition: test_cache.py:67