ATLAS Offline Software
Namespaces | Classes | Functions | Variables
python.tests Namespace Reference

Namespaces

 PyTestsLib
 
 PyTHistTestsLib
 
 test_CA
 

Classes

class  test_McAodBuilder
 
class  test_McAodFilter
 
class  test_McAodValidation
 
class  xcode
 

Functions

def iov_ranges (iovs)
 
def create_database ()
 
def teardown_database ()
 
def test_database_creation ()
 
def test_database_creation_unicode ()
 
def test_database_retrieval ()
 
def create_defect_type (ddb, n)
 
def create_defect_type_unicode (ddb, n, desc)
 
def test_defect_creation ()
 
def test_virtual_defects_invert ()
 
def test_defect_insertion_retrieval ()
 
def test_defect_insertion_retrieval_unicode ()
 
def test_defect_failure_nonascii_name ()
 
def test_defect_mangle_bad_stored_unicode ()
 
def test_defect_empty_retrieval ()
 
def test_virtual_defect_creation ()
 
def test_defect_list_update_on_creation ()
 
def test_virtual_defect_list_update_on_creation ()
 
def test_virtual_defect_creation_unicode ()
 
def test_virtual_defect_failure_nonascii_name ()
 
def test_nonpresent ()
 
def test_many_sparse_channels ()
 
def test_virtual_defects ()
 
def test_virtual_defects_deep ()
 
def test_virtual_defects_stress ()
 
def test_virtual_defect_hiding ()
 
def test_update_virtual_defect ()
 
def test_tagging_unicode ()
 
def test_rename_defects ()
 
def iov_result_depends (iovs)
 
def test_ignore_defects ()
 
def test_query_with_primary_dependencies ()
 
def test_independent_tags ()
 
def test_query_with_primary_dependencies_with_ignore ()
 
def test_virtual_defect_consistency ()
 
def test_iov_tag_defects ()
 
def test_intersect ()
 
def test_normalize_defect_names ()
 
def test_reject_duplicate_names ()
 
def test_get_intolerable_defects ()
 
def test_list_empty_tag ()
 
def test_noncontiguous_defectid_creation ()
 
def test_return_types ()
 
def mungline (f)
 
def shortDescription (self)
 
def invariant (test_data_name)
 

Variables

 log
 
string TEST_DATABASE = "test_defects.db/COMP200"
 
 teardown_db = None
 
 g = list(globals().keys())
 
 _shortDescription
 
 shortDescription
 
string not_yet
 

Function Documentation

◆ create_database()

def python.tests.create_database ( )

Definition at line 27 of file DataQuality/DQDefects/python/tests/__init__.py.

27 def create_database():
28  ddb = DefectsDB(TEST_DATABASE, read_only=False, create=True)
29  global teardown_db
30  teardown_db = ddb
31 

◆ create_defect_type()

def python.tests.create_defect_type (   ddb,
  n 
)

Definition at line 67 of file DataQuality/DQDefects/python/tests/__init__.py.

67 def create_defect_type(ddb, n):
68  defect_name = "DQD_TEST_DEFECT_%i" % n
69  ddb.create_defect(defect_name, "A test defect (%i)" % n)
70  return defect_name
71 

◆ create_defect_type_unicode()

def python.tests.create_defect_type_unicode (   ddb,
  n,
  desc 
)

Definition at line 72 of file DataQuality/DQDefects/python/tests/__init__.py.

72 def create_defect_type_unicode(ddb, n, desc):
73  defect_name = "DQD_TEST_DEFECT_%i" % n
74  ddb.create_defect(defect_name, desc)
75  return defect_name
76 
77 @with_setup(create_database, teardown_database)

◆ invariant()

def python.tests.invariant (   test_data_name)

Definition at line 8 of file DataQuality/DQUtils/python/tests.py.

8 def invariant(test_data_name):
9  def wrapper(func):
10  testfile = "%s.%s" % (func.__name__, test_data_name)
11  @wraps(func)
12  def check_invariant(*args, **kwargs):
13  result = func(*args, **kwargs)
14  if "DQU_UPDATE_TEST_DATA" in environ:
15  with open(test_data_name, "wb") as fd:
16  dump(result, fd)
17  print("Wrote updated test data")
18  else:
19  test_data = loads(resource_string("testdata", testfile))
20  assert result == test_data, "Data considered 'invariant' has changed"
21  return check_invariant
22 
23  return wrapper

◆ iov_ranges()

def python.tests.iov_ranges (   iovs)

Definition at line 23 of file DataQuality/DQDefects/python/tests/__init__.py.

23 def iov_ranges(iovs):
24  return [(i.since, i.until) for i in iovs]
25 

◆ iov_result_depends()

def python.tests.iov_result_depends (   iovs)

Definition at line 634 of file DataQuality/DQDefects/python/tests/__init__.py.

634 def iov_result_depends(iovs):
635  caused_bad = set()
636  for iov in iovs:
637  if iov.user == "sys:virtual":
638  caused_bad |= set(iov.comment.split())
639  return caused_bad
640 
641 @with_setup(create_database, teardown_database)

◆ mungline()

def python.tests.mungline (   f)

Definition at line 1042 of file DataQuality/DQDefects/python/tests/__init__.py.

1042  def mungline (f):
1043  f.func_code = xcode(f)

◆ shortDescription()

def python.tests.shortDescription (   self)

Definition at line 1053 of file DataQuality/DQDefects/python/tests/__init__.py.

1053  def shortDescription (self):
1054  desc = self._shortDescription()
1055  if desc is None:
1056  desc = self.test.shortDescription()
1057  return desc

◆ teardown_database()

def python.tests.teardown_database ( )

Definition at line 32 of file DataQuality/DQDefects/python/tests/__init__.py.

32 def teardown_database():
33  # force garbage collection before database teardown so as not to create
34  # lots of .__afs* files.
35  global teardown_db
36  teardown_db._clear_connections()
37  teardown_db = None
38  from gc import collect
39  collect()
40 
41  connection_string = "/".join(TEST_DATABASE.split("/")[:-1])
42  if connection_string.endswith(".db"):
43  log.info("Deleting %s", connection_string)
44  unlink(connection_string)
45  return
46 
47  msg = "I don't know how to tear down %s" % TEST_DATABASE
48  log.fatal(msg)
49  raise NotImplementedError(msg)
50 
51 @with_setup(create_database, teardown_database)

◆ test_database_creation()

def python.tests.test_database_creation ( )

Definition at line 52 of file DataQuality/DQDefects/python/tests/__init__.py.

53  assert exists("test_defects.db")
54  log.info("Created database %s", TEST_DATABASE)
55 
56 @with_setup(create_database, teardown_database)

◆ test_database_creation_unicode()

def python.tests.test_database_creation_unicode ( )

Definition at line 57 of file DataQuality/DQDefects/python/tests/__init__.py.

58  assert exists("test_defects.db")
59  log.info("Created database %s", six.ensure_text(TEST_DATABASE))
60 
61 @with_setup(create_database, teardown_database)

◆ test_database_retrieval()

def python.tests.test_database_retrieval ( )

Definition at line 62 of file DataQuality/DQDefects/python/tests/__init__.py.

63  ddb = DefectsDB(TEST_DATABASE)
64  defects = ddb.retrieve()
65  assert len(defects) == 0, "Unexpected records on the database"
66 

◆ test_defect_creation()

def python.tests.test_defect_creation ( )

Definition at line 78 of file DataQuality/DQDefects/python/tests/__init__.py.

79  ddb = DefectsDB(TEST_DATABASE, read_only=False)
80  create_defect_type(ddb, 0)
81 
82  assert len(ddb.defect_ids) == 1
83 
84 
85 @with_setup(create_database, teardown_database)

◆ test_defect_empty_retrieval()

def python.tests.test_defect_empty_retrieval ( )

Definition at line 240 of file DataQuality/DQDefects/python/tests/__init__.py.

241  ddb = DefectsDB(TEST_DATABASE, read_only=False)
242  iovs = ddb.retrieve()
243  assert not iovs
244 
245  # Create two defects
246  create_defect_type(ddb, 0)
247  create_defect_type(ddb, 1)
248 
249  # Make a virtual defect whose result is the combination of the above
250  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
251  "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
252 
253  iovs = ddb.retrieve()
254  assert not iovs
255 
256 @with_setup(create_database, teardown_database)

◆ test_defect_failure_nonascii_name()

def python.tests.test_defect_failure_nonascii_name ( )
Check that we raise an error if the defect name is not ASCII

Definition at line 194 of file DataQuality/DQDefects/python/tests/__init__.py.

195  """
196  Check that we raise an error if the defect name is not ASCII
197  """
198  if six.PY3:
199  import ROOT
200  if ROOT.gROOT.GetVersionInt() < 62000:
201  # Passing str objects using multibyte encodings is broken
202  # with pyroot up to 6.18. Should be fixed in 6.20?
203  return
204  ddb = DefectsDB(TEST_DATABASE, read_only=False)
205 
206  ddb.create_defect(u"DQD_TÉST_DÉFÉCT_0", "Test")
207 
208 @with_setup(create_database, teardown_database)

◆ test_defect_insertion_retrieval()

def python.tests.test_defect_insertion_retrieval ( )

Definition at line 136 of file DataQuality/DQDefects/python/tests/__init__.py.

137  ddb = DefectsDB(TEST_DATABASE, read_only=False)
138 
139  TEST_ID = 0
140  TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID
141  TEST_COMMENT = "First test defect"
142  TEST_USER = "DQDefects.tests"
143  TEST_SINCE, TEST_UNTIL = 0, 100
144 
145  create_defect_type(ddb, TEST_ID)
146 
147  ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER)
148 
149  iovs = ddb.retrieve()
150 
151  assert len(iovs) == 1
152  iov = iovs[0]
153  assert iov.since == TEST_SINCE
154  assert iov.until == TEST_UNTIL
155  assert iov.channel == TEST_DEFECT_NAME
156  assert iov.present
157  assert not iov.recoverable
158  assert iov.user == TEST_USER
159  assert iov.comment == TEST_COMMENT
160 
161 @with_setup(create_database, teardown_database)

◆ test_defect_insertion_retrieval_unicode()

def python.tests.test_defect_insertion_retrieval_unicode ( )

Definition at line 162 of file DataQuality/DQDefects/python/tests/__init__.py.

163  if six.PY3:
164  import ROOT
165  if ROOT.gROOT.GetVersionInt() < 62000:
166  # Passing str objects using multibyte encodings is broken
167  # with pyroot up to 6.18. Should be fixed in 6.20?
168  return
169  ddb = DefectsDB(TEST_DATABASE, read_only=False)
170 
171  TEST_ID = 0
172  TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID
173  TEST_COMMENT = u"First test defect with character: ±"
174  TEST_USER = u"DQDefécts.tests"
175  TEST_SINCE, TEST_UNTIL = 0, 100
176  TEST_DEFECT_DESCRIPTION = u"À test defect (%i)" % TEST_ID
177 
178  create_defect_type_unicode(ddb, TEST_ID, TEST_DEFECT_DESCRIPTION)
179 
180  ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER)
181 
182  iovs = ddb.retrieve()
183 
184  assert len(iovs) == 1
185  iov = iovs[0]
186  assert iov.present
187  assert not iov.recoverable
188  assert iov.user == TEST_USER
189  assert iov.comment == TEST_COMMENT
190  assert ddb.all_defect_descriptions[TEST_DEFECT_NAME] == TEST_DEFECT_DESCRIPTION
191 
192 @raises(UnicodeEncodeError)
193 @with_setup(create_database, teardown_database)

◆ test_defect_list_update_on_creation()

def python.tests.test_defect_list_update_on_creation ( )
Check that the defect name list is updated when a defect is created

Definition at line 279 of file DataQuality/DQDefects/python/tests/__init__.py.

280  """
281  Check that the defect name list is updated when a defect is created
282  """
283  ddb = DefectsDB(TEST_DATABASE, read_only=False)
284  name = create_defect_type(ddb, 0)
285 
286  assert ddb.defect_names == set([name])
287 
288 @with_setup(create_database, teardown_database)

◆ test_defect_mangle_bad_stored_unicode()

def python.tests.test_defect_mangle_bad_stored_unicode ( )
Check that we recover if any of the string payloads are bad UTF-8

Definition at line 209 of file DataQuality/DQDefects/python/tests/__init__.py.

210  """
211  Check that we recover if any of the string payloads are bad UTF-8
212  """
213  if six.PY3:
214  import ROOT
215  if ROOT.gROOT.GetVersionInt() < 62000:
216  # Passing str objects using multibyte encodings is broken
217  # with pyroot up to 6.18. Should be fixed in 6.20?
218  return
219  ddb = DefectsDB(TEST_DATABASE, read_only=False)
220 
221  TEST_DEFECT_NAME = 'DQD_TEST_DEFECT_0'
222  TEST_SINCE, TEST_UNTIL = 0, 100
223 
224  ddb.create_defect(TEST_DEFECT_NAME, "Test")
225 
226  store = ddb.defects_folder.storeObject
227  p = ddb._defect_payload
228  p["present"] = True
229  p["recoverable"] = False
230  p["user"] = b'\x80abc'
231  p["comment"] = b'\x80abc'
232 
233  defect_id = ddb.defect_chan_as_id(TEST_DEFECT_NAME, True)
234 
235  store(TEST_SINCE, TEST_UNTIL, p, defect_id, ddb.defects_tag, False)
236  iovs = ddb.retrieve()
237  assert(iovs[0].user == '\\x80abc' and iovs[0].comment == '\\x80abc')
238 
239 @with_setup(create_database, teardown_database)

◆ test_get_intolerable_defects()

def python.tests.test_get_intolerable_defects ( )
Check that the intolerable defect listing function works

Definition at line 921 of file DataQuality/DQDefects/python/tests/__init__.py.

922  '''
923  Check that the intolerable defect listing function works
924  '''
925  ddb = DefectsDB(TEST_DATABASE, read_only=False)
926 
927  # Create some primary defects
928  create_defect_type(ddb, 0)
929  create_defect_type(ddb, 1)
930  create_defect_type(ddb, 2)
931  create_defect_type(ddb, 3)
932 
933  # Make some virtual defects
934  ddb.new_virtual_defect("DQD_TEST_Virtual_DEFECT", "Comment",
935  "DQD_TEST_DEFECT_0")
936  ddb.new_virtual_defect("PRIMARY", "Comment",
937  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
938  ddb.new_virtual_defect("PHYS_test", "Comment",
939  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 DQD_TEST_DEFECT_2")
940  ddb.new_virtual_defect("TIGHT", "Comment",
941  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 DQD_TEST_DEFECT_2 DQD_TEST_DEFECT_3")
942 
943  # old_primary_only should be True here, so PRIMARY gives the set of defects
944  assert sorted(ddb.get_intolerable_defects()) == ["DQD_TEST_DEFECT_0", "DQD_TEST_DEFECT_1"], "default params/old_primary_only check failed"
945  assert sorted(ddb.get_intolerable_defects(old_primary_only=False, exclude=['TIGHT'])) == ["DQD_TEST_DEFECT_0", "DQD_TEST_DEFECT_1", "DQD_TEST_DEFECT_2"], 'old_primary_only=False check failed'
946  assert sorted(ddb.get_intolerable_defects(old_primary_only=False)) == ["DQD_TEST_DEFECT_0", "DQD_TEST_DEFECT_1"], 'regex handling check failed'
947 
948 @with_setup(create_database, teardown_database)

◆ test_ignore_defects()

def python.tests.test_ignore_defects ( )

Definition at line 642 of file DataQuality/DQDefects/python/tests/__init__.py.

642 def test_ignore_defects():
643 
644  ddb = DefectsDB(TEST_DATABASE, read_only=False)
645 
646  # Create two defects
647  create_defect_type(ddb, 0)
648  create_defect_type(ddb, 1)
649  create_defect_type(ddb, 2)
650 
651  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
652  ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
653  ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "")
654 
655  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
656  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 DQD_TEST_DEFECT_2")
657 
658  ignored_defects = set(["DQD_TEST_DEFECT_1"])
659 
660  iovs = ddb.retrieve()
661  assert iov_result_depends(iovs) & ignored_defects, "test is broken"
662 
663  iovs = ddb.retrieve(ignore=ignored_defects)
664  assert not iov_result_depends(iovs) & ignored_defects, "result depends on ignored defects"
665 
666 @with_setup(create_database, teardown_database)

◆ test_independent_tags()

def python.tests.test_independent_tags ( )

Definition at line 691 of file DataQuality/DQDefects/python/tests/__init__.py.

692 
693  ddb = DefectsDB(TEST_DATABASE, read_only=False)
694 
695  # Create two defects
696  create_defect_type(ddb, 0)
697  create_defect_type(ddb, 1)
698  create_defect_type(ddb, 2)
699 
700  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
701  ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
702  ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "")
703 
704  dtag1 = ddb.new_defects_tag("dqd-test", "New iov tag")
705 
706  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "", present=False)
707 
708  dtag2 = ddb.new_defects_tag("dqd-test-2", "New iov tag")
709 
710  # Make a virtual defect whose result is the combination of the above
711  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
712  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
713 
714  ltag1 = ddb.new_logics_tag()
715 
716  ddb.update_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
717  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_2")
718 
719  ltag2 = ddb.new_logics_tag()
720 
721  assert ltag1 != ltag2, f'{ltag1} and {ltag2} should be different'
722 
723  iovs = DefectsDB(TEST_DATABASE, tag=("HEAD", ltag1)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
724  assert iov_ranges(iovs) == [(100, 200)], str(iov_ranges(iovs))
725 
726  iovs = DefectsDB(TEST_DATABASE, tag=("HEAD", ltag2)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
727  assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))
728 
729  iovs = DefectsDB(TEST_DATABASE, tag=(dtag1, ltag1)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
730  assert iov_ranges(iovs) == [(0, 100), (100, 200)], str(iov_ranges(iovs))
731 
732  iovs = DefectsDB(TEST_DATABASE, tag=(dtag2, ltag2)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
733  assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))
734 
735  htag = ddb.new_hierarchical_tag(dtag2, ltag2)
736 
737  iovs = DefectsDB(TEST_DATABASE, tag=(htag, htag)).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
738  assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))
739 
740  iovs = DefectsDB(TEST_DATABASE, tag=htag).retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
741  assert iov_ranges(iovs) == [(200, 300)], str(iov_ranges(iovs))
742 
743 @with_setup(create_database, teardown_database)

◆ test_intersect()

def python.tests.test_intersect ( )

Definition at line 818 of file DataQuality/DQDefects/python/tests/__init__.py.

818 def test_intersect():
819 
820  ddb = DefectsDB(TEST_DATABASE, read_only=False)
821 
822  # Create two defects
823  create_defect_type(ddb, 0)
824  create_defect_type(ddb, 1)
825  create_defect_type(ddb, 2)
826 
827  ddb.insert("DQD_TEST_DEFECT_0", 0, 1000, "", "")
828  ddb.insert("DQD_TEST_DEFECT_0", 1000, 2000, "", "")
829 
830  iovs = ddb.retrieve(50, 100, intersect=True)
831  assert len(iovs) == 1
832  assert (iovs[0].since, iovs[0].until) == (50, 100)
833 
834  iovs = ddb.retrieve(999, 1001, intersect=True)
835  assert len(iovs) == 2
836  first, second = iovs
837  assert (first.since, first.until) == (999, 1000)
838  assert (second.since, second.until) == (1000, 1001)
839 
840 @with_setup(create_database, teardown_database)

◆ test_iov_tag_defects()

def python.tests.test_iov_tag_defects ( )

Definition at line 783 of file DataQuality/DQDefects/python/tests/__init__.py.

784  log.info('IOV Tags')
785  ddb = DefectsDB(TEST_DATABASE, read_only=False)
786 
787  # Create two defects
788  create_defect_type(ddb, 0)
789  create_defect_type(ddb, 1)
790  create_defect_type(ddb, 2)
791 
792  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "comment1", "user1", present=False)
793  ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
794  ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "comment2", "user2", recoverable=True)
795 
796  ddb.new_defects_tag("dqd-test", "New iov tag",
797  iovranges=[(0, 51),
798  ((0,210), (0,306))])
799  ddb2 = DefectsDB(TEST_DATABASE, tag=('DetStatusDEFECTS-dqd-test','HEAD'))
800  iovs = ddb2.retrieve(nonpresent=True)
801  assert len(iovs) == 2
802  assert ((iovs[0].channel, iovs[0].since, iovs[0].until,
803  iovs[0].present, iovs[0].recoverable, iovs[0].user,
804  iovs[0].comment)
805  ==
806  ('DQD_TEST_DEFECT_0', 0, 51,
807  False, False, 'user1',
808  'comment1'))
809  assert ((iovs[1].channel, iovs[1].since, iovs[1].until,
810  iovs[1].present, iovs[1].recoverable, iovs[1].user,
811  iovs[1].comment)
812  ==
813  ('DQD_TEST_DEFECT_2', 210, 300,
814  True, True, 'user2',
815  'comment2'))
816 
817 @with_setup(create_database, teardown_database)

◆ test_list_empty_tag()

def python.tests.test_list_empty_tag ( )
Checking that listing a tag works even if the tag is empty

Definition at line 949 of file DataQuality/DQDefects/python/tests/__init__.py.

949 def test_list_empty_tag():
950  """
951  Checking that listing a tag works even if the tag is empty
952  """
953  ddb = DefectsDB(TEST_DATABASE, read_only=False, tag="nominal")
954  ddb.virtual_defect_names
955 
956 @with_setup(create_database, teardown_database)

◆ test_many_sparse_channels()

def python.tests.test_many_sparse_channels ( )

Definition at line 359 of file DataQuality/DQDefects/python/tests/__init__.py.

360  "Testing many virtual channels with sparsely placed IoVs"
361  ddb = DefectsDB(TEST_DATABASE, read_only=False)
362  all_defects = []
363  for i in range(52):
364  all_defects.append(create_defect_type(ddb, i*2))
365 
366  with ddb.storage_buffer:
367  for i in all_defects:
368  ddb.insert(i, 0, 100, "Test", "DQDefects.tests")
369 
370  queried_defects = all_defects[:-1]
371  result = ddb.retrieve(channels=queried_defects)
372  queried_defects_set = set(queried_defects)
373  result_defects_set = set(i.channel for i in result)
374 
375  unwanted_defects_set = result_defects_set - queried_defects_set
376  assert not unwanted_defects_set, "Unwanted defects: %r" % unwanted_defects_set
377 
378  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment",
379  " ".join(all_defects))
380 
381  result = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
382  assert result.channels == set(["DQD_TEST_VIRTUAL_DEFECT"])
383  assert len(result) == 1
384  # This assumes evaluate_full == True
385  assert result[0].comment == " ".join(sorted(all_defects)), result[0].comment
386 
387  result = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"],
388  evaluate_full=False)
389 
390  assert result.channels == set(["DQD_TEST_VIRTUAL_DEFECT"])
391  assert len(result) == 1
392 
393 @with_setup(create_database, teardown_database)

◆ test_noncontiguous_defectid_creation()

def python.tests.test_noncontiguous_defectid_creation ( )
Test that defects are inserted correctly into non-contiguous ranges

Definition at line 957 of file DataQuality/DQDefects/python/tests/__init__.py.

958  """
959  Test that defects are inserted correctly into non-contiguous ranges
960  """
961  ddb = DefectsDB(TEST_DATABASE, read_only=False)
962 
963  create_defect_type(ddb, 0)
964  ddb._create_defect_with_id(2, "TEST_DEFECT_DQD_2", "")
965  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
966  "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2")
967  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2",
968  "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2")
969  create_defect_type(ddb, 1)
970  create_defect_type(ddb, 3)
971  # assert primary and virtual defects are right
972  ids, names, m = ddb.get_channels()
973  assert m == {0: 'DQD_TEST_DEFECT_0', 1: 'DQD_TEST_DEFECT_1', 2: 'TEST_DEFECT_DQD_2', 3: 'DQD_TEST_DEFECT_3', 'DQD_TEST_DEFECT_3': 3, 'DQD_TEST_DEFECT_0': 0, 'DQD_TEST_DEFECT_1': 1, 'TEST_DEFECT_DQD_2': 2}, 'Primary defect problem'
974  ids, names, m = ddb.get_virtual_channels()
975  assert m == {2147483648: 'DQD_TEST_VIRTUAL_DEFECT', 2147483649: 'DQD_TEST_VIRTUAL_DEFECT_2', 'DQD_TEST_VIRTUAL_DEFECT': 2147483648, 'DQD_TEST_VIRTUAL_DEFECT_2': 2147483649}, 'Virtual defect problem'
976 
977 @with_setup(create_database, teardown_database)

◆ test_nonpresent()

def python.tests.test_nonpresent ( )

Definition at line 341 of file DataQuality/DQDefects/python/tests/__init__.py.

341 def test_nonpresent():
342  ddb = DefectsDB(TEST_DATABASE, read_only=False)
343 
344  create_defect_type(ddb, 0)
345 
346  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests")
347  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests", present=False)
348 
349  iovs = ddb.retrieve()
350 
351  assert len(iovs) == 0
352 
353  iovs = ddb.retrieve(nonpresent=True)
354 
355  assert len(iovs) == 1
356  assert not iovs[0].present
357 
358 @with_setup(create_database, teardown_database)

◆ test_normalize_defect_names()

def python.tests.test_normalize_defect_names ( )

Definition at line 841 of file DataQuality/DQDefects/python/tests/__init__.py.

842  ddb = DefectsDB(TEST_DATABASE, read_only=False)
843 
844  # Create two defects
845  create_defect_type(ddb, 0)
846  create_defect_type(ddb, 1)
847 
848  # Make a virtual defect whose result is the combination of the above
849  ddb.new_virtual_defect("DQD_TEST_Virtual_DEFECT", "Comment",
850  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
851 
852  assert ddb.normalize_defect_names('dQd_tEsT_DeFeCt_0')=='DQD_TEST_DEFECT_0'
853  assert ddb.normalize_defect_names(['dQd_tEsT_DeFeCt_0', 'DqD_TeSt_dEfEcT_1'])==['DQD_TEST_DEFECT_0', 'DQD_TEST_DEFECT_1']
854  assert ddb.normalize_defect_names('dqd_test_virtual_defect')=='DQD_TEST_Virtual_DEFECT'
855  try:
856  ddb.normalize_defect_names('does_not_exist')
857  wasthrown = False
858  except DefectUnknownError:
859  wasthrown = True
860  assert wasthrown, 'normalize_defect_names should throw when the defect does not exist'
861 
862 @with_setup(create_database, teardown_database)

◆ test_query_with_primary_dependencies()

def python.tests.test_query_with_primary_dependencies ( )

Definition at line 667 of file DataQuality/DQDefects/python/tests/__init__.py.

668 
669  ddb = DefectsDB(TEST_DATABASE, read_only=False)
670 
671  # Create two defects
672  defect_names = [create_defect_type(ddb, i) for i in range(3)]
673 
674  for i, defect in enumerate(defect_names):
675  ddb.insert(defect, i*100, (i+1)*100, "", "")
676 
677  ddb.new_virtual_defect("DQD_TEST_VDEFECT", "", " ".join(defect_names))
678 
679  iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"])
680  assert iovs.channels == set(["DQD_TEST_VDEFECT"])
681  assert len(iovs) == len(defect_names)
682 
683  iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"],
684  with_primary_dependencies=True)
685  assert iovs.channels == set(["DQD_TEST_VDEFECT"] + defect_names), (
686  "Check failed.")
687 
688  assert len(iovs) == len(defect_names)*2
689 
690 @with_setup(create_database, teardown_database)

◆ test_query_with_primary_dependencies_with_ignore()

def python.tests.test_query_with_primary_dependencies_with_ignore ( )
Checking with_primary_dependencies + ignore

Checks that the set of channels and iovs returned contains the correct 
number of channels and iovs when specifying both with_primary_dependencies 
and ignore to DQDefects.Retrieve

Definition at line 744 of file DataQuality/DQDefects/python/tests/__init__.py.

745  """
746  Checking with_primary_dependencies + ignore
747 
748  Checks that the set of channels and iovs returned contains the correct
749  number of channels and iovs when specifying both with_primary_dependencies
750  and ignore to DQDefects.Retrieve
751  """
752 
753  ddb = DefectsDB(TEST_DATABASE, read_only=False)
754 
755  # Create two defects
756  defect_names = [create_defect_type(ddb, i) for i in range(3)]
757 
758  for i, defect in enumerate(defect_names):
759  ddb.insert(defect, i*100, (i+1)*100, "", "")
760 
761  ignored = set(defect_names[:1])
762 
763  ddb.new_virtual_defect("DQD_TEST_VDEFECT", "", " ".join(defect_names))
764 
765  iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"], ignore=ignored)
766  assert iovs.channels == set(["DQD_TEST_VDEFECT"])
767  assert len(iovs) == len(defect_names)-1
768 
769  iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"], ignore=ignored,
770  with_primary_dependencies=True)
771  assert iovs.channels == set(["DQD_TEST_VDEFECT"] + defect_names) - ignored, (
772  "Check failed.")
773 
774  assert len(iovs) == len(defect_names[1:])*2
775 

◆ test_reject_duplicate_names()

def python.tests.test_reject_duplicate_names ( )

Definition at line 863 of file DataQuality/DQDefects/python/tests/__init__.py.

864  ddb = DefectsDB(TEST_DATABASE, read_only=False)
865 
866  ddb.create_defect('A_TEST_DEFECT', 'A test defect')
867 
868  wasthrown = False
869  try:
870  ddb.create_defect('A_TEST_DEFECT', 'A test defect 2')
871  except DefectExistsError:
872  wasthrown = True
873  assert wasthrown, 'Creation of duplicate defects should throw'
874 
875  wasthrown = False
876  try:
877  ddb.create_defect('A_test_defect', 'A test defect 2')
878  except DefectExistsError:
879  wasthrown = True
880  assert wasthrown, 'Creation of duplicate defects should throw, even with different case'
881 
882  wasthrown = False
883  try:
884  ddb.create_defect('A_test_defect_2', 'A test defect 2')
885  ddb.rename_defect('A_test_defect_2', 'A_TEST_DEFECT')
886  except DefectExistsError:
887  wasthrown = True
888  assert wasthrown, 'Rename of defect to existing defect name should throw'
889 
890  ddb.new_virtual_defect('TEST_VIRTUAL_DEFECT', 'Comment', 'A_TEST_DEFECT')
891  wasthrown = False
892  try:
893  ddb.new_virtual_defect('Test_Virtual_Defect', 'Comment', 'A_TEST_DEFECT')
894  except DefectExistsError:
895  wasthrown = True
896  assert wasthrown, 'Creation of duplicate virtual defects should throw'
897 
898  ddb.new_virtual_defect('Test_Virtual_Defect_2', 'Comment', 'A_TEST_DEFECT')
899  wasthrown = False
900  try:
901  ddb.rename_defect('Test_Virtual_Defect_2', 'TEST_VIRTUAL_DEFECT')
902  except DefectExistsError:
903  wasthrown = True
904  assert wasthrown, 'Rename of virtual defect to existing virtual defect name should throw'
905 
906  wasthrown = False
907  try:
908  ddb.rename_defect('Test_Virtual_Defect_2', 'A_TEST_DEFECT')
909  except DefectExistsError:
910  wasthrown = True
911  assert wasthrown, 'Rename of virtual defect to existing defect name should throw'
912 
913  wasthrown = False
914  try:
915  ddb.rename_defect('A_TEST_DEFECT', 'TEST_VIRTUAL_DEFECT')
916  except DefectExistsError:
917  wasthrown = True
918  assert wasthrown, 'Rename of defect to existing virtual defect name should throw'
919 
920 @with_setup(create_database, teardown_database)

◆ test_rename_defects()

def python.tests.test_rename_defects ( )

Definition at line 578 of file DataQuality/DQDefects/python/tests/__init__.py.

578 def test_rename_defects():
579 
580  ddb = DefectsDB(TEST_DATABASE, read_only=False)
581 
582  # Create two defects
583  create_defect_type(ddb, 0)
584  create_defect_type(ddb, 1)
585 
586  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
587  ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
588 
589  defects_tag = ddb.new_defects_tag("dqd-test", "New iov tag")
590 
591  # Make a virtual defect whose result is the combination of the above
592  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
593  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
594  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2", "",
595  "DQD_TEST_VIRTUAL_DEFECT")
596  # Make ones with inversion logic
597  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_3", "",
598  "DQD_TEST_DEFECT_0 !DQD_TEST_DEFECT_1")
599  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_4", "",
600  "!DQD_TEST_VIRTUAL_DEFECT")
601 
602  original_tag = ddb.new_logics_tag()
603  original_htag = ddb.new_hierarchical_tag(defects_tag, original_tag)
604 
605  # The following is no longer considered an error condition
606 
612 
613  # first rename a primary defect
614  ddb.rename_defect("DQD_TEST_DEFECT_0", "DQD_TEST_DEFECT_3")
615  assert ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT'].clauses == ['DQD_TEST_DEFECT_3', 'DQD_TEST_DEFECT_1'], ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT'].clauses
616  assert ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_3'].clauses == ['DQD_TEST_DEFECT_3', '!DQD_TEST_DEFECT_1'], ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_3'].clauses
617 
618  # also valid in other tags?
619  ddb2 = DefectsDB(TEST_DATABASE, tag=original_htag)
620  assert ddb2.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT'].clauses == ['DQD_TEST_DEFECT_3', 'DQD_TEST_DEFECT_1'], ddb2.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT'].clauses
621 
622  # Now try to rename a virtual defect
623  ddb.rename_defect("DQD_TEST_VIRTUAL_DEFECT", "DQD_TEST_VIRTUAL_DEFECT_A")
624 
625  assert ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_2'].clauses == ['DQD_TEST_VIRTUAL_DEFECT_A'], ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_2'].clauses
626  assert ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_4'].clauses == ['!DQD_TEST_VIRTUAL_DEFECT_A'], ddb.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_4'].clauses
627 
628  # also valid in other tags?
629  ddb2 = DefectsDB(TEST_DATABASE, tag=original_htag)
630  assert ddb2.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_2'].clauses == ['DQD_TEST_VIRTUAL_DEFECT_A'], ddb2.virtual_defect_logics['DQD_TEST_VIRTUAL_DEFECT_2'].clauses
631 
632  ddb._virtual_defect_consistency_check()
633 

◆ test_return_types()

def python.tests.test_return_types ( )
Test that return types are appropriate

Definition at line 978 of file DataQuality/DQDefects/python/tests/__init__.py.

978 def test_return_types():
979  """
980  Test that return types are appropriate
981  """
982  ddb = DefectsDB(TEST_DATABASE, read_only=False)
983 
984  # Create a defect
985  create_defect_type(ddb, 0)
986  did = ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
987  "Comment", "DQD_TEST_DEFECT_0")
988  assert type(did) == int
989 
990  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
991 
992  dtag = ddb.new_defects_tag("dqd-test", "New iov tag")
993  assert type(dtag) == str, f'{type(dtag)} instead of str'
994  ltag = ddb.new_logics_tag()
995  assert type(ltag) == str
996  htag = ddb.new_hierarchical_tag(dtag, ltag)
997  assert type(htag) == str
998 
999  assert type(ddb.defects_tags) == list, f'{type(ddb.defects_tags)} instead of list'
1000  assert type(ddb.defects_tags[0]) == str, f'{type(ddb.defects_tags[0])} instead of str'
1001  assert type(ddb.logics_tags) == list, f'{type(ddb.logics_tags)} instead of list'
1002  assert type(ddb.logics_tags[0]) == str, f'{type(ddb.logics_tags[0])} instead of str'
1003  assert type(ddb.tags) == list, f'{type(ddb.tags)} instead of list'
1004  assert type(ddb.tags[0]) == str, f'{type(ddb.tags[0])} instead of str'
1005 
1006  ids, names, _ = ddb.get_channels()
1007  ids = set(ids); names = set(names) # Duplicate so we don't stomp on the underlying data
1008  assert type(ids.pop()) == int
1009  assert type(names.pop()) == str
1010  ids, names, _ = ddb.get_virtual_channels()
1011  ids = set(ids); names = set(names)
1012  assert type(ids.pop()) == int
1013  assert type(names.pop()) == str
1014 
1015  iov = ddb.retrieve()
1016  assert type(iov[0].channel) == str
1017  assert type(iov[0].comment) == str
1018  assert type(iov[0].user) == str
1019  assert type(iov[0].present) == bool
1020  assert type(iov[0].recoverable) == bool
1021 
1022  assert type(ddb.all_defect_descriptions["DQD_TEST_DEFECT_0"]) == str, str(ddb.all_defect_descriptions)
1023  assert type(ddb.all_defect_descriptions["DQD_TEST_VIRTUAL_DEFECT"]) == str, str(ddb.all_defect_descriptions)
1024 
1025  ddb2 = DefectsDB(TEST_DATABASE, read_only=False, tag=htag)
1026  assert type(ddb2.defects_tag) == str
1027  assert type(ddb2.logics_tag) == str
1028  assert type(ddb2.tag.defects) == str
1029  assert type(ddb2.tag.logic) == str
1030 
1031 
1032 # nose 1.6.3 is missing a few fixes that were in nose 1.3.7...

◆ test_tagging_unicode()

def python.tests.test_tagging_unicode ( )

Definition at line 549 of file DataQuality/DQDefects/python/tests/__init__.py.

550 
551  ddb = DefectsDB(TEST_DATABASE, read_only=False)
552 
553  # Create two defects
554  create_defect_type(ddb, 0)
555  create_defect_type(ddb, 1)
556 
557  ddb.insert(u"DQD_TEST_DEFECT_0", 0, 100, u"", u"")
558  ddb.insert(u"DQD_TEST_DEFECT_1", 100, 200, u"", u"")
559 
560  defects_tag = ddb.new_defects_tag("dqd-test", u"New iov tag")
561 
562  # Make a virtual defect whose result is the combination of the above
563  ddb.new_virtual_defect(u"DQD_TEST_VIRTUAL_DEFECT", u"",
564  u"DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
565 
566  original_tag = ddb.new_logics_tag()
567  original_htag = ddb.new_hierarchical_tag(defects_tag, original_tag)
568 
569  what = {"channels": [u"DQD_TEST_VIRTUAL_DEFECT"]}
570 
571  orig_iovs = DefectsDB((TEST_DATABASE), tag=six.ensure_text(original_htag)).retrieve(**what)
572 
573  assert len(orig_iovs) == 2
574  assert (orig_iovs[0].since, orig_iovs[0].until) == ( 0, 100)
575  assert (orig_iovs[1].since, orig_iovs[1].until) == (100, 200)
576 
577 @with_setup(create_database, teardown_database)

◆ test_update_virtual_defect()

def python.tests.test_update_virtual_defect ( )

Definition at line 502 of file DataQuality/DQDefects/python/tests/__init__.py.

503 
504  ddb = DefectsDB(TEST_DATABASE, read_only=False)
505 
506  # Create two defects
507  create_defect_type(ddb, 0)
508  create_defect_type(ddb, 1)
509  create_defect_type(ddb, 2)
510 
511  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "")
512  ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "")
513  ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "")
514 
515  defects_tag = ddb.new_defects_tag("dqd-test", "New iov tag")
516 
517  # Make a virtual defect whose result is the combination of the above
518  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "",
519  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
520 
521  original_tag = ddb.new_logics_tag()
522  original_htag = ddb.new_hierarchical_tag(defects_tag, original_tag)
523 
524  ddb.update_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
525  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_2")
526 
527  new_tag = ddb.new_logics_tag()
528  new_htag = ddb.new_hierarchical_tag(defects_tag, new_tag)
529 
530  what = {"channels": ["DQD_TEST_VIRTUAL_DEFECT"]}
531 
532  orig_iovs = DefectsDB(TEST_DATABASE, tag=original_htag).retrieve(**what)
533  new_iovs = DefectsDB(TEST_DATABASE, tag=new_htag).retrieve(**what)
534  head_iovs = DefectsDB(TEST_DATABASE).retrieve(**what)
535 
536  assert head_iovs == new_iovs
537  assert head_iovs != orig_iovs
538 
539  assert len(head_iovs) == 2
540  assert (head_iovs[0].since, head_iovs[0].until) == ( 0, 100)
541  assert (head_iovs[1].since, head_iovs[1].until) == (200, 300)
542 
543  from DQUtils.db import Databases
544  db3 = Databases.get_instance(TEST_DATABASE, read_only=True)
545  pfs = db3.getFolderSet('/GLOBAL/DETSTATUS')
546  assert pfs.tagDescription(new_htag) != '', 'Hierarchical tag description not created'
547 
548 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_consistency()

def python.tests.test_virtual_defect_consistency ( )
Checking that virtual flags don't depend on non-existent flags

Definition at line 776 of file DataQuality/DQDefects/python/tests/__init__.py.

777  """
778  Checking that virtual flags don't depend on non-existent flags
779  """
780  DefectsDB()._virtual_defect_consistency_check()
781 
782 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_creation()

def python.tests.test_virtual_defect_creation ( )

Definition at line 257 of file DataQuality/DQDefects/python/tests/__init__.py.

258 
259  ddb = DefectsDB(TEST_DATABASE, read_only=False)
260 
261  # Create two defects
262  create_defect_type(ddb, 0)
263  create_defect_type(ddb, 1)
264 
265  # Make a virtual defect whose result is the combination of the above
266  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
267  "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
268 
269  # First test ensures internals are correct
270  assert len(ddb.virtual_defect_ids) == 1
271  assert "DQD_TEST_VIRTUAL_DEFECT" in ddb.virtual_defect_names
272 
273  # Second test to ensure database is in correct state
274  ddb = DefectsDB(TEST_DATABASE)
275  assert len(ddb.virtual_defect_ids) == 1
276  assert "DQD_TEST_VIRTUAL_DEFECT" in ddb.virtual_defect_names
277 
278 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_creation_unicode()

def python.tests.test_virtual_defect_creation_unicode ( )

Definition at line 301 of file DataQuality/DQDefects/python/tests/__init__.py.

302 
303  ddb = DefectsDB(TEST_DATABASE, read_only=False)
304 
305  # Create two defects
306  create_defect_type(ddb, 0)
307  create_defect_type(ddb, 1)
308 
309  # Make a virtual defect whose result is the combination of the above
310  ddb.new_virtual_defect(u"DQD_TEST_VIRTUAL_DEFECT",
311  u"Comment", u"DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
312 
313  # First test ensures internals are correct
314  assert len(ddb.virtual_defect_ids) == 1
315  assert "DQD_TEST_VIRTUAL_DEFECT" in ddb.virtual_defect_names
316 
317  # Second test to ensure database is in correct state
318  ddb = DefectsDB(TEST_DATABASE)
319  assert len(ddb.virtual_defect_ids) == 1
320  assert "DQD_TEST_VIRTUAL_DEFECT" in ddb.virtual_defect_names
321 
322 @raises(UnicodeEncodeError)
323 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_failure_nonascii_name()

def python.tests.test_virtual_defect_failure_nonascii_name ( )
Check that we raise an error if the virtual defect name is not ASCII

Definition at line 324 of file DataQuality/DQDefects/python/tests/__init__.py.

325  """
326  Check that we raise an error if the virtual defect name is not ASCII
327  """
328  if six.PY3:
329  import ROOT
330  if ROOT.gROOT.GetVersionInt() < 62000:
331  # Passing str objects using multibyte encodings is broken
332  # with pyroot up to 6.18. Should be fixed in 6.20?
333  return
334  ddb = DefectsDB(TEST_DATABASE, read_only=False)
335 
336  ddb.create_defect(u"DQD_TEST_DEFECT_0", "Test")
337  ddb.new_virtual_defect(u"DQD_TÉST_VIRTUAL_DÉFÉCT",
338  u"Comment", u"DQD_TEST_DEFECT_0")
339 
340 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_hiding()

def python.tests.test_virtual_defect_hiding ( )

Definition at line 482 of file DataQuality/DQDefects/python/tests/__init__.py.

483  ddb = DefectsDB(TEST_DATABASE, read_only=False)
484 
485  # Create two defects
486  create_defect_type(ddb, 0)
487  create_defect_type(ddb, 1)
488 
489  # Make a virtual defect whose result is the combination of the above
490  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment",
491  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
492 
493  new_tag = ddb.new_logics_tag()
494 
495  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2", "Comment",
496  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
497 
498  ddb2 = DefectsDB(TEST_DATABASE, tag=('HEAD', new_tag), read_only=True)
499  assert ddb2.virtual_defect_names == set(['DQD_TEST_VIRTUAL_DEFECT']), 'Only one virtual defect should be in this tag'
500 
501 @with_setup(create_database, teardown_database)

◆ test_virtual_defect_list_update_on_creation()

def python.tests.test_virtual_defect_list_update_on_creation ( )
Check that the virtual defect name list is updated when a defect is created

Definition at line 289 of file DataQuality/DQDefects/python/tests/__init__.py.

290  """
291  Check that the virtual defect name list is updated when a defect is created
292  """
293  ddb = DefectsDB(TEST_DATABASE, read_only=False)
294  name = create_defect_type(ddb, 0)
295  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
296  "Comment", name)
297 
298  assert ddb.virtual_defect_names == set(["DQD_TEST_VIRTUAL_DEFECT"])
299 
300 @with_setup(create_database, teardown_database)

◆ test_virtual_defects()

def python.tests.test_virtual_defects ( )

Definition at line 394 of file DataQuality/DQDefects/python/tests/__init__.py.

395  "Testing virtual defect basics"
396  ddb = DefectsDB(TEST_DATABASE, read_only=False)
397 
398  # Create two defects
399  create_defect_type(ddb, 0)
400  create_defect_type(ddb, 1)
401 
402  # Make a virtual defect whose result is the combination of the above
403  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment",
404  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
405 
406  # Insert an iov into each
407  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests")
408  ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests")
409 
410  # See what the result of the virtual defect is
411  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
412 
413  # Tests against the value
414  assert len(iovs) == 2
415  first, second = iovs
416  assert (first.since, first.until) == (0, 100)
417  assert (second.since, second.until) == (150, 200)
418  assert first.channel == second.channel == "DQD_TEST_VIRTUAL_DEFECT"
419  del first, second, iovs
420 
421  # Now unset the present bit, and test again that the relevant preiod is fixed
422  ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests", present=False)
423 
424  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
425 
426  assert len(iovs) == 1
427  first = iovs[0]
428  assert (first.since, first.until) == (0, 100)
429  assert first.channel == "DQD_TEST_VIRTUAL_DEFECT"
430 
431  # Now extend the defect and see if we get a contiguous result
432  ddb.insert("DQD_TEST_DEFECT_0", 100, 150, "Test", "DQDefects.tests")
433  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
434 
435  assert len(iovs) == 1
436  first = iovs[0]
437  assert (first.since, first.until) == (0, 150)
438  assert first.channel == "DQD_TEST_VIRTUAL_DEFECT"
439 
440 @with_setup(create_database, teardown_database)

◆ test_virtual_defects_deep()

def python.tests.test_virtual_defects_deep ( )

Definition at line 441 of file DataQuality/DQDefects/python/tests/__init__.py.

442  ddb = DefectsDB(TEST_DATABASE, read_only=False)
443 
444  # Create two defects
445  create_defect_type(ddb, 0)
446  create_defect_type(ddb, 1)
447 
448  # Insert an iov into each
449  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests")
450  ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests")
451 
452  # Make a virtual defect whose result is the combination of the above
453  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_0", "", "DQD_TEST_DEFECT_0")
454  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_1", "", "DQD_TEST_DEFECT_1")
455 
456  ddb = DefectsDB(TEST_DATABASE)
457 
458  ddb.retrieve()
459 
460 @with_setup(create_database, teardown_database)

◆ test_virtual_defects_invert()

def python.tests.test_virtual_defects_invert ( )

Definition at line 86 of file DataQuality/DQDefects/python/tests/__init__.py.

87  "Testing virtual defects involving inversion"
88  ddb = DefectsDB(TEST_DATABASE, read_only=False)
89 
90  # Create two defects
91  create_defect_type(ddb, 0)
92  create_defect_type(ddb, 1)
93  create_defect_type(ddb, 2)
94 
95  # Make a virtual defect whose result is the combination of the above
96  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment",
97  "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 !DQD_TEST_DEFECT_2")
98 
99  # Insert an iov into each
100  ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests")
101  ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests")
102  ddb.insert("DQD_TEST_DEFECT_2", 50, 125, "Test", "DQDefects.tests")
103 
104  # See what the result of the virtual defect is
105  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
106 
107  # Tests against the value
108  assert len(iovs) == 4, list(iovs)
109  first, second, third, fourth = iovs
110  assert (first.since, first.until) == (0, 50), first
111  assert (second.since, second.until) == (50, 100), second
112  assert (third.since, third.until) == (125, 150), third
113  assert (fourth.since, fourth.until) == (150, 200), fourth
114  assert first.channel == second.channel == third.channel == fourth.channel == "DQD_TEST_VIRTUAL_DEFECT", (first.channel, second.channel, third.channel, fourth.channel)
115  del first, second, third, fourth, iovs
116 
117  # Test evaluate_full=False
118  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"], evaluate_full=False)
119  assert len(iovs) == 2, list(iovs)
120 
121  # Now unset the present bit
122  ddb.insert("DQD_TEST_DEFECT_2", 50, 150, "Test", "DQDefects.tests", present=False)
123  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
124 
125  # here we are sensitive to details of python ordering ...
126  assert len(iovs) == 3, list(iovs)
127  first, second, third = iovs
128  assert (first.since, first.until) == (0, 100), first
129  assert (second.since, second.until) == (100, 150), second
130  assert (third.since, third.until) == (150, 200), third
131  assert first.channel == second.channel == third.channel == "DQD_TEST_VIRTUAL_DEFECT", (first.channel, second.channel, third.channel)
132  del first, second, third, iovs
133 
134 
135 @with_setup(create_database, teardown_database)

◆ test_virtual_defects_stress()

def python.tests.test_virtual_defects_stress ( )

Definition at line 461 of file DataQuality/DQDefects/python/tests/__init__.py.

462  ddb = DefectsDB(TEST_DATABASE, read_only=False)
463 
464  STRESS_COUNT = 20
465 
466  for i in range(STRESS_COUNT):
467  create_defect_type(ddb, i)
468 
469  with ddb.storage_buffer:
470  for i in range(STRESS_COUNT):
471  ddb.insert("DQD_TEST_DEFECT_%i" % i, i, i+1, "Test", "DQDefects.tests")
472 
473  ALL_DEFECTS = " ".join("DQD_TEST_DEFECT_%i" % i for i in range(STRESS_COUNT))
474  ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "", ALL_DEFECTS)
475 
476  iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
477 
478  assert len(iovs) == STRESS_COUNT - 1
479  assert (iovs[0].since, iovs[-1].until) == (1, STRESS_COUNT)
480 
481 @with_setup(create_database, teardown_database)

Variable Documentation

◆ _shortDescription

python.tests._shortDescription
private

◆ g

python.tests.g = list(globals().keys())

◆ log

python.tests.log

◆ not_yet

string python.tests.not_yet

◆ shortDescription

python.tests.shortDescription

◆ teardown_db

python.tests.teardown_db = None

◆ TEST_DATABASE

string python.tests.TEST_DATABASE = "test_defects.db/COMP200"
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.tests.test_reject_duplicate_names
def test_reject_duplicate_names()
Definition: DataQuality/DQDefects/python/tests/__init__.py:863
python.tests.test_database_retrieval
def test_database_retrieval()
Definition: DataQuality/DQDefects/python/tests/__init__.py:62
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
python.tests.test_return_types
def test_return_types()
Definition: DataQuality/DQDefects/python/tests/__init__.py:978
python.tests.test_virtual_defect_failure_nonascii_name
def test_virtual_defect_failure_nonascii_name()
Definition: DataQuality/DQDefects/python/tests/__init__.py:324
python.tests.mungline
def mungline(f)
Definition: DataQuality/DQDefects/python/tests/__init__.py:1042
python.tests.test_normalize_defect_names
def test_normalize_defect_names()
Definition: DataQuality/DQDefects/python/tests/__init__.py:841
python.tests.test_defect_empty_retrieval
def test_defect_empty_retrieval()
Definition: DataQuality/DQDefects/python/tests/__init__.py:240
python.tests.test_ignore_defects
def test_ignore_defects()
Definition: DataQuality/DQDefects/python/tests/__init__.py:642
python.tests.create_database
def create_database()
Definition: DataQuality/DQDefects/python/tests/__init__.py:27
python.tests.teardown_database
def teardown_database()
Definition: DataQuality/DQDefects/python/tests/__init__.py:32
python.tests.test_tagging_unicode
def test_tagging_unicode()
Definition: DataQuality/DQDefects/python/tests/__init__.py:549
python.tests.invariant
def invariant(test_data_name)
Definition: DataQuality/DQUtils/python/tests.py:8
python.tests.test_many_sparse_channels
def test_many_sparse_channels()
Definition: DataQuality/DQDefects/python/tests/__init__.py:359
python.tests.test_database_creation
def test_database_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:52
python.tests.test_virtual_defect_consistency
def test_virtual_defect_consistency()
Definition: DataQuality/DQDefects/python/tests/__init__.py:776
python.tests.test_nonpresent
def test_nonpresent()
Definition: DataQuality/DQDefects/python/tests/__init__.py:341
python.tests.test_rename_defects
def test_rename_defects()
Definition: DataQuality/DQDefects/python/tests/__init__.py:578
python.tests.iov_result_depends
def iov_result_depends(iovs)
Definition: DataQuality/DQDefects/python/tests/__init__.py:634
python.tests.test_defect_creation
def test_defect_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:78
python.tests.test_query_with_primary_dependencies_with_ignore
def test_query_with_primary_dependencies_with_ignore()
Definition: DataQuality/DQDefects/python/tests/__init__.py:744
python.tests.shortDescription
def shortDescription(self)
Definition: DataQuality/DQDefects/python/tests/__init__.py:1053
python.tests.test_defect_mangle_bad_stored_unicode
def test_defect_mangle_bad_stored_unicode()
Definition: DataQuality/DQDefects/python/tests/__init__.py:209
python.tests.test_noncontiguous_defectid_creation
def test_noncontiguous_defectid_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:957
python.tests.create_defect_type_unicode
def create_defect_type_unicode(ddb, n, desc)
Definition: DataQuality/DQDefects/python/tests/__init__.py:72
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.tests.test_list_empty_tag
def test_list_empty_tag()
Definition: DataQuality/DQDefects/python/tests/__init__.py:949
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.ChapPy.dump
def dump(buf, stdout=sys.stdout)
Definition: ChapPy.py:25
python.tests.test_virtual_defect_creation
def test_virtual_defect_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:257
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
python.tests.test_defect_insertion_retrieval
def test_defect_insertion_retrieval()
Definition: DataQuality/DQDefects/python/tests/__init__.py:136
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.tests.test_defect_failure_nonascii_name
def test_defect_failure_nonascii_name()
Definition: DataQuality/DQDefects/python/tests/__init__.py:194
python.tests.test_virtual_defects_invert
def test_virtual_defects_invert()
Definition: DataQuality/DQDefects/python/tests/__init__.py:86
python.tests.test_query_with_primary_dependencies
def test_query_with_primary_dependencies()
Definition: DataQuality/DQDefects/python/tests/__init__.py:667
python.tests.test_virtual_defects_stress
def test_virtual_defects_stress()
Definition: DataQuality/DQDefects/python/tests/__init__.py:461
python.tests.test_virtual_defect_creation_unicode
def test_virtual_defect_creation_unicode()
Definition: DataQuality/DQDefects/python/tests/__init__.py:301
python.tests.test_virtual_defect_hiding
def test_virtual_defect_hiding()
Definition: DataQuality/DQDefects/python/tests/__init__.py:482
Trk::open
@ open
Definition: BinningType.h:40
python.tests.test_get_intolerable_defects
def test_get_intolerable_defects()
Definition: DataQuality/DQDefects/python/tests/__init__.py:921
python.tests.test_defect_list_update_on_creation
def test_defect_list_update_on_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:279
python.tests.test_defect_insertion_retrieval_unicode
def test_defect_insertion_retrieval_unicode()
Definition: DataQuality/DQDefects/python/tests/__init__.py:162
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.tests.test_intersect
def test_intersect()
Definition: DataQuality/DQDefects/python/tests/__init__.py:818
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
Trig::FeatureAccessImpl::collect
void collect(const HLT::TriggerElement *te, std::vector< Trig::Feature< T > > &data, const std::string &label, unsigned int condition, const std::string &teName, const HLT::TrigNavStructure *navstructure)
actual feature acceess implementation It has (thanks to the ClassTraits) functionality to flatten con...
Definition: FeatureCollectAthena.h:299
python.tests.test_update_virtual_defect
def test_update_virtual_defect()
Definition: DataQuality/DQDefects/python/tests/__init__.py:502
python.tests.create_defect_type
def create_defect_type(ddb, n)
Definition: DataQuality/DQDefects/python/tests/__init__.py:67
python.tests.test_independent_tags
def test_independent_tags()
Definition: DataQuality/DQDefects/python/tests/__init__.py:691
str
Definition: BTagTrackIpAccessor.cxx:11
python.tests.test_iov_tag_defects
def test_iov_tag_defects()
Definition: DataQuality/DQDefects/python/tests/__init__.py:783
python.tests.test_virtual_defects
def test_virtual_defects()
Definition: DataQuality/DQDefects/python/tests/__init__.py:394
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
python.tests.iov_ranges
def iov_ranges(iovs)
Definition: DataQuality/DQDefects/python/tests/__init__.py:23
python.tests.test_virtual_defects_deep
def test_virtual_defects_deep()
Definition: DataQuality/DQDefects/python/tests/__init__.py:441
python.tests.test_database_creation_unicode
def test_database_creation_unicode()
Definition: DataQuality/DQDefects/python/tests/__init__.py:57
python.tests.test_virtual_defect_list_update_on_creation
def test_virtual_defect_list_update_on_creation()
Definition: DataQuality/DQDefects/python/tests/__init__.py:289