def test_query(self, api): if api == 'dqsegdb': result = query_dqsegdb(self.TEST_CLASS.query, QUERY_FLAGS, 0, 10) RESULT = QUERY_RESULTC else: result = query_segdb(self.TEST_CLASS.query, QUERY_FLAGS, 0, 10, url='https://geosegdb.does.not.exist') RESULT = QUERY_RESULT assert isinstance(result, self.TEST_CLASS) utils.assert_dict_equal(result, RESULT, utils.assert_flag_equal)
def test_query(self, api): if api == 'dqsegdb': result = query_dqsegdb(self.TEST_CLASS.query, QUERY_FLAGS, 0, 10) RESULT = QUERY_RESULTC else: result = query_segdb(self.TEST_CLASS.query, QUERY_FLAGS, 0, 10, url='https://segdb.does.not.exist') RESULT = QUERY_RESULT assert isinstance(result, self.TEST_CLASS) utils.assert_dict_equal(result, RESULT, utils.assert_flag_equal)
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_dqsegdb(self): result = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, QUERY_FLAGS, 0, 10) RESULT = QUERY_RESULTC assert isinstance(result, self.TEST_CLASS) utils.assert_dict_equal(result, RESULT, utils.assert_flag_equal) # check all values of on_error with pytest.warns(UserWarning) as record: result = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, QUERY_FLAGS + ['X1:BLAHBLAH:1'], 0, 10, on_error='warn') result = query_dqsegdb(self.TEST_CLASS.query_dqsegdb, QUERY_FLAGS + ['X1:BLAHBLAH:1'], 0, 10, on_error='ignore') utils.assert_dict_equal(result, RESULT, utils.assert_flag_equal) assert len(record) == 1 # check on_error='ignore' didn't warn with pytest.raises(ValueError): self.TEST_CLASS.query_dqsegdb(QUERY_FLAGS, 0, 10, on_error='blah')
def test_sub(self, instance, reverse): a = instance.copy() a -= reverse utils.assert_dict_equal(a, instance - reverse, utils.assert_flag_equal)
def _assert(a, b): return utils.assert_dict_equal(a, b, utils.assert_flag_equal)
def test_invert(self, instance): inverse = type(instance)() for key in instance: inverse[key] = ~instance[key] utils.assert_dict_equal(~instance, inverse, utils.assert_flag_equal)
def test_xor(self, instance, reverse): a = instance.copy(deep=True) a ^= reverse utils.assert_dict_equal(a, instance ^ reverse, utils.assert_flag_equal)
def test_sub(self, instance, reverse): a = instance.copy(deep=True) a -= reverse utils.assert_dict_equal(a, instance - reverse, utils.assert_flag_equal)
def test_or(self, instance, reverse): a = instance.copy() a |= reverse utils.assert_dict_equal(a, instance | reverse, utils.assert_flag_equal)
def test_query_segdb(self): result = query_segdb(self.TEST_CLASS.query_segdb, QUERY_FLAGS, 0, 10) assert isinstance(result, self.TEST_CLASS) utils.assert_dict_equal(result, QUERY_RESULT, utils.assert_flag_equal)
def test_and(self, instance, reverse): a = instance.copy() a &= reverse utils.assert_dict_equal(a, instance & reverse, utils.assert_flag_equal)