Skip to content

Commit

Permalink
gwpy.io: silence some NDS2 host warnings
Browse files Browse the repository at this point in the history
by default GWpy will _always_ emit a warning whenever you try to dynamically work out the NDS2 host for a non-LIGO interferometer. This commit changes the default behaviour such that if `NDSSERVER` is set (or similar), then a warning will not be emitted.
  • Loading branch information
duncanmmacleod committed Oct 17, 2018
1 parent dca49aa commit 0a1c7dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gwpy/io/nds2.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ def host_resolution_order(ifo, env='NDSSERVER', epoch='now',
try:
host, port = DEFAULT_HOSTS[difo]
except KeyError:
warnings.warn('No default host found for ifo %r' % ifo)
# unknown default NDS2 host for detector, if we don't have
# hosts already defined (either by NDSSERVER or similar)
# we should warn the user
if not hosts:
warnings.warn('No default host found for ifo %r' % ifo)
else:
if (host, port) not in hosts:
hosts.append((host, port))
Expand Down
6 changes: 5 additions & 1 deletion gwpy/io/tests/test_nds2.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ def test_nds2_host_order():
('nds.ligo.caltech.edu', 31200)]

# test warnings for unknown IFO
with pytest.warns(UserWarning):
with pytest.warns(UserWarning) as record:
# should produce warning
hro = io_nds2.host_resolution_order('X1')
assert hro == [('nds.ligo.caltech.edu', 31200)]
# should _not_ produce warning
hro = io_nds2.host_resolution_order('X1', env='TESTENV')
assert len(record) == 1 # make sure only one warning was emitted


@skip_missing_dependency('nds2')
Expand Down

0 comments on commit 0a1c7dc

Please sign in to comment.