def test_query_dqsegdb(self, name, flag): result = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, 0, 10) RESULT = QUERY_RESULTC[flag] assert isinstance(result, self.TEST_CLASS) utils.assert_segmentlist_equal(result.known, RESULT.known) utils.assert_segmentlist_equal(result.active, RESULT.active) result2 = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, (0, 10)) utils.assert_flag_equal(result, result2) result2 = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, SegmentList([(0, 10)])) utils.assert_flag_equal(result, result2) with pytest.raises(ValueError): query_dqsegdb(self.TEST_CLASS.query_dqsegdb, 'BAD-FLAG_NAME', SegmentList([(0, 10)])) with pytest.raises(HTTPError) as exc: query_dqsegdb(self.TEST_CLASS.query_dqsegdb, 'X1:GWPY-TEST:0', 0, 10) assert str(exc.value) == 'HTTP Error 404: Not found [X1:GWPY-TEST:0]' with pytest.raises(TypeError): self.TEST_CLASS.query_dqsegdb(QUERY_FLAGS[0], 1, 2, 3) with pytest.raises(TypeError): self.TEST_CLASS.query_dqsegdb(QUERY_FLAGS[0], (1, 2, 3))
def test_pad(self, flag): # test with no arguments (and no padding) padded = flag.pad() utils.assert_flag_equal(flag, padded) # test with padding flag.padding = PADDING padded = flag.pad() utils.assert_segmentlist_equal(padded.known, KNOWNPAD) utils.assert_segmentlist_equal(padded.active, ACTIVEPAD) # test with arguments flag.padding = None padded = flag.pad(*PADDING) utils.assert_segmentlist_equal(padded.known, KNOWNPAD) utils.assert_segmentlist_equal(padded.active, ACTIVEPAD) # test in-place padded = flag.pad(*PADDING) assert padded is not flag padded = flag.pad(*PADDING, inplace=True) assert padded is flag utils.assert_segmentlist_equal(flag.known, KNOWNPAD) utils.assert_segmentlist_equal(flag.active, ACTIVEPAD) # check that other keyword arguments get rejected appropriately with pytest.raises(TypeError): flag.pad(*PADDING, kwarg='test')
def test_populate(self): name = QUERY_FLAGS[0] flag = self.TEST_CLASS(name, known=QUERY_RESULT[name].known) with mock.patch('dqsegdb.apicalls.dqsegdbQueryTimes', mocks.dqsegdb_query_times(QUERY_RESULT)): flag.populate() utils.assert_flag_equal(flag, QUERY_RESULTC[name])
def test_query_segdb(self): result = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], 0, 10) RESULT = QUERY_RESULT[QUERY_FLAGS[0]] assert isinstance(result, self.TEST_CLASS) utils.assert_segmentlist_equal(result.known, RESULT.known) utils.assert_segmentlist_equal(result.active, RESULT.active) result2 = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], (0, 10)) utils.assert_flag_equal(result, result2) result2 = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], SegmentList([(0, 10)])) utils.assert_flag_equal(result, result2)
def test_populate(self): def fake(): return self.TEST_CLASS({ x: self.ENTRY_CLASS(name=x, known=y.known) for x, y in QUERY_RESULT.items() }) # build fake veto definer file vdf = fake() vdf2 = fake() vdf3 = fake() flag = QUERY_FLAGS[0] vdf2[flag].padding = (-1, 1) span = SegmentList([Segment(0, 2)]) # and populate using a mocked query with mock.patch('dqsegdb.apicalls.dqsegdbQueryTimes', mocks.dqsegdb_query_times(QUERY_RESULT)): vdf.populate() vdf2.populate() vdf3.populate(segments=span) # test warnings on bad entries vdf['TEST'] = self.ENTRY_CLASS('X1:BLAHBLAHBLAH:1', known=[(0, 1)]) with pytest.warns(UserWarning) as record: vdf.populate(on_error='warn') vdf.populate(on_error='ignore') assert len(record) == 1 vdf.pop('TEST') with pytest.raises(ValueError): vdf.populate(on_error='blah') # check basic populate worked utils.assert_dict_equal(vdf, QUERY_RESULTC, utils.assert_flag_equal) # check padded populate worked utils.assert_flag_equal(vdf2[flag], QUERY_RESULTC[flag].pad(-1, 1)) # check segment-restricted populate worked for flag in vdf3: utils.assert_segmentlist_equal(vdf3[flag].known, QUERY_RESULTC[flag].known & span) utils.assert_segmentlist_equal(vdf3[flag].active, QUERY_RESULTC[flag].active & span)
def test_populate(self): def fake(): return self.TEST_CLASS({ x: self.ENTRY_CLASS(name=x, known=y.known) for x, y in QUERY_RESULT.items()}) # build fake veto definer file vdf = fake() vdf2 = fake() vdf3 = fake() flag = QUERY_FLAGS[0] vdf2[flag].padding = (-1, 1) span = SegmentList([Segment(0, 2)]) # and populate using a mocked query with mock.patch('dqsegdb.apicalls.dqsegdbQueryTimes', mocks.dqsegdb_query_times(QUERY_RESULT)): vdf.populate() vdf2.populate() vdf3.populate(segments=span) # test warnings on bad entries vdf['TEST'] = self.ENTRY_CLASS('X1:BLAHBLAHBLAH:1', known=[(0, 1)]) with pytest.warns(UserWarning) as record: vdf.populate(on_error='warn') vdf.populate(on_error='ignore') assert len(record) == 1 vdf.pop('TEST') with pytest.raises(ValueError): vdf.populate(on_error='blah') # check basic populate worked utils.assert_dict_equal(vdf, QUERY_RESULTC, utils.assert_flag_equal) # check padded populate worked utils.assert_flag_equal(vdf2[flag], QUERY_RESULTC[flag].pad(-1, 1)) # check segment-restricted populate worked for flag in vdf3: utils.assert_segmentlist_equal( vdf3[flag].known, QUERY_RESULTC[flag].known & span) utils.assert_segmentlist_equal( vdf3[flag].active, QUERY_RESULTC[flag].active & span)
def test_query_segdb(self): result = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], 0, 10) RESULT = QUERY_RESULT[QUERY_FLAGS[0]] assert isinstance(result, self.TEST_CLASS) utils.assert_segmentlist_equal(result.known, RESULT.known) utils.assert_segmentlist_equal(result.active, RESULT.active) result2 = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], (0, 10)) utils.assert_flag_equal(result, result2) result2 = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS[0], SegmentList([(0, 10)])) utils.assert_flag_equal(result, result2) with pytest.raises(TypeError): self.TEST_CLASS.query_segdb(QUERY_FLAGS[0], 1, 2, 3) with pytest.raises(TypeError): self.TEST_CLASS.query_segdb(QUERY_FLAGS[0], (1, 2, 3))
def test_query_dqsegdb(self, name, flag): result = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, 0, 10) RESULT = QUERY_RESULTC[flag] assert isinstance(result, self.TEST_CLASS) utils.assert_segmentlist_equal(result.known, RESULT.known) utils.assert_segmentlist_equal(result.active, RESULT.active) result2 = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, (0, 10)) utils.assert_flag_equal(result, result2) result2 = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, name, SegmentList([(0, 10)])) utils.assert_flag_equal(result, result2) with pytest.raises(ValueError): query_dqsegdb(self.TEST_CLASS.query_dqsegdb, 'BAD-FLAG_NAME', SegmentList([(0, 10)])) with pytest.raises(HTTPError) as exc: query_dqsegdb(self.TEST_CLASS.query_dqsegdb, 'X1:GWPY-TEST:0', 0, 10) assert str(exc.value) == 'HTTP Error 404: Not found [X1:GWPY-TEST:0]'
def test_isub(self, instance, reverse): a = instance.copy() a -= reverse keys = list(a.keys()) utils.assert_flag_equal(a[keys[0]], instance[keys[0]] - reverse[keys[1]])