ATLAS Offline Software
Loading...
Searching...
No Matches
python.tests Namespace Reference

Namespaces

namespace  PyTestsLib
namespace  PyTHistTestsLib
namespace  test_CA

Functions

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

Variables

 log
str TEST_DATABASE = "test_defects.db/COMP200"
 teardown_db = None

Function Documentation

◆ create_database()

python.tests.create_database ( )

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

24def create_database():
25 ddb = DefectsDB(TEST_DATABASE, read_only=False, create=True)
26 global teardown_db
27 teardown_db = ddb
28

◆ create_defect_type()

python.tests.create_defect_type ( ddb,
n )

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

90def create_defect_type(ddb, n):
91 defect_name = "DQD_TEST_DEFECT_%i" % n
92 ddb.create_defect(defect_name, "A test defect (%i)" % n)
93 return defect_name
94

◆ create_defect_type_unicode()

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

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

95def create_defect_type_unicode(ddb, n, desc):
96 defect_name = "DQD_TEST_DEFECT_%i" % n
97 ddb.create_defect(defect_name, desc)
98 return defect_name
99
100@test()

◆ invariant()

python.tests.invariant ( test_data_name)

Definition at line 8 of file tests.py.

8def 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
void print(char *figname, TCanvas *c1)
-event-from-file

◆ iov_ranges()

python.tests.iov_ranges ( iovs)

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

20def iov_ranges(iovs):
21 return [(i.since, i.until) for i in iovs]
22

◆ iov_result_depends()

python.tests.iov_result_depends ( iovs)

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

633def iov_result_depends(iovs):
634 caused_bad = set()
635 for iov in iovs:
636 if iov.user == "sys:virtual":
637 caused_bad |= set(iov.comment.split())
638 return caused_bad
639
640@test()
STL class.

◆ raises()

python.tests.raises ( exc)

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

60def raises(exc):
61 def decorator(fn):
62 def testfunc():
63 caught = False
64 try:
65 fn()
66 except exc:
67 caught = True
68 assert caught, f'Failed to raise exception {exc}'
69 return testfunc
70 return decorator
71
72
73@test()

◆ teardown_database()

python.tests.teardown_database ( )

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

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

◆ test()

python.tests.test ( )

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

49def test():
50 def decorator(fn):
51 def test_fn(self):
52 create_database()
53 fn()
54 teardown_database()
55 return type(fn.__name__, (unittest.TestCase,),
56 {fn.__name__ : test_fn})
57 return decorator
58
59

◆ test_database_creation()

python.tests.test_database_creation ( )

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

74def test_database_creation():
75 assert exists("test_defects.db")
76 log.info("Created database %s", TEST_DATABASE)
77
78
79@test()
bool exists(const std::string &filename)
does a file exist

◆ test_database_creation_unicode()

python.tests.test_database_creation_unicode ( )

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

80def test_database_creation_unicode():
81 assert exists("test_defects.db")
82 log.info("Created database %s", TEST_DATABASE)
83
84@test()

◆ test_database_retrieval()

python.tests.test_database_retrieval ( )

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

85def test_database_retrieval():
86 ddb = DefectsDB(TEST_DATABASE)
87 defects = ddb.retrieve()
88 assert len(defects) == 0, "Unexpected records on the database"
89

◆ test_defect_creation()

python.tests.test_defect_creation ( )

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

101def test_defect_creation():
102 ddb = DefectsDB(TEST_DATABASE, read_only=False)
103 create_defect_type(ddb, 0)
104
105 assert len(ddb.defect_ids) == 1
106
107
108@test()

◆ test_defect_empty_retrieval()

python.tests.test_defect_empty_retrieval ( )

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

245def test_defect_empty_retrieval():
246 ddb = DefectsDB(TEST_DATABASE, read_only=False)
247 iovs = ddb.retrieve()
248 assert not iovs
249
250 # Create two defects
251 create_defect_type(ddb, 0)
252 create_defect_type(ddb, 1)
253
254 # Make a virtual defect whose result is the combination of the above
255 ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
256 "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1")
257
258 iovs = ddb.retrieve()
259 assert not iovs
260
261@test()

◆ test_defect_failure_nonascii_name()

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

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

211def test_defect_failure_nonascii_name():
212 """
213 Check that we raise an error if the defect name is not ASCII
214 """
215 ddb = DefectsDB(TEST_DATABASE, read_only=False)
216
217 ddb.create_defect(u"DQD_TÉST_DÉFÉCT_0", "Test")
218
219@test()

◆ test_defect_insertion_retrieval()

python.tests.test_defect_insertion_retrieval ( )

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

159def test_defect_insertion_retrieval():
160 ddb = DefectsDB(TEST_DATABASE, read_only=False)
161
162 TEST_ID = 0
163 TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID
164 TEST_COMMENT = "First test defect"
165 TEST_USER = "DQDefects.tests"
166 TEST_SINCE, TEST_UNTIL = 0, 100
167
168 create_defect_type(ddb, TEST_ID)
169
170 ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER)
171
172 iovs = ddb.retrieve()
173
174 assert len(iovs) == 1
175 iov = iovs[0]
176 assert iov.since == TEST_SINCE
177 assert iov.until == TEST_UNTIL
178 assert iov.channel == TEST_DEFECT_NAME
179 assert iov.present
180 assert not iov.recoverable
181 assert iov.user == TEST_USER
182 assert iov.comment == TEST_COMMENT
183
184@test()

◆ test_defect_insertion_retrieval_unicode()

python.tests.test_defect_insertion_retrieval_unicode ( )

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

185def test_defect_insertion_retrieval_unicode():
186 ddb = DefectsDB(TEST_DATABASE, read_only=False)
187
188 TEST_ID = 0
189 TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID
190 TEST_COMMENT = u"First test defect with character: ±"
191 TEST_USER = u"DQDefécts.tests"
192 TEST_SINCE, TEST_UNTIL = 0, 100
193 TEST_DEFECT_DESCRIPTION = u"À test defect (%i)" % TEST_ID
194
195 create_defect_type_unicode(ddb, TEST_ID, TEST_DEFECT_DESCRIPTION)
196
197 ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER)
198
199 iovs = ddb.retrieve()
200
201 assert len(iovs) == 1
202 iov = iovs[0]
203 assert iov.present
204 assert not iov.recoverable
205 assert iov.user == TEST_USER
206 assert iov.comment == TEST_COMMENT
207 assert ddb.all_defect_descriptions[TEST_DEFECT_NAME] == TEST_DEFECT_DESCRIPTION
208
209@test()
210@raises(UnicodeEncodeError)

◆ test_defect_list_update_on_creation()

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

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

284def test_defect_list_update_on_creation():
285 """
286 Check that the defect name list is updated when a defect is created
287 """
288 ddb = DefectsDB(TEST_DATABASE, read_only=False)
289 name = create_defect_type(ddb, 0)
290
291 assert ddb.defect_names == set([name])
292
293@test()

◆ test_defect_mangle_bad_stored_unicode()

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 220 of file DataQuality/DQDefects/python/tests/__init__.py.

220def test_defect_mangle_bad_stored_unicode():
221 """
222 Check that we recover if any of the string payloads are bad UTF-8
223 """
224 ddb = DefectsDB(TEST_DATABASE, read_only=False)
225
226 TEST_DEFECT_NAME = 'DQD_TEST_DEFECT_0'
227 TEST_SINCE, TEST_UNTIL = 0, 100
228
229 ddb.create_defect(TEST_DEFECT_NAME, "Test")
230
231 store = ddb.defects_folder.storeObject
232 p = ddb._defect_payload
233 p["present"] = True
234 p["recoverable"] = False
235 p["user"] = b'\x80abc'
236 p["comment"] = b'\x80abc'
237
238 defect_id = ddb.defect_chan_as_id(TEST_DEFECT_NAME, True)
239
240 store(TEST_SINCE, TEST_UNTIL, p, defect_id, ddb.defects_tag, False)
241 iovs = ddb.retrieve()
242 assert(iovs[0].user == '\\x80abc' and iovs[0].comment == '\\x80abc')
243
244@test()

◆ test_get_intolerable_defects()

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

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

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

◆ test_ignore_defects()

python.tests.test_ignore_defects ( )

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

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

◆ test_independent_tags()

python.tests.test_independent_tags ( )

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

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

◆ test_intersect()

python.tests.test_intersect ( )

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

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

◆ test_iov_tag_defects()

python.tests.test_iov_tag_defects ( )

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

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

◆ test_list_empty_tag()

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

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

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

◆ test_many_sparse_channels()

python.tests.test_many_sparse_channels ( )

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

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

◆ test_noncontiguous_defectid_creation()

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

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

956def test_noncontiguous_defectid_creation():
957 """
958 Test that defects are inserted correctly into non-contiguous ranges
959 """
960 ddb = DefectsDB(TEST_DATABASE, read_only=False)
961
962 create_defect_type(ddb, 0)
963 ddb._create_defect_with_id(2, "TEST_DEFECT_DQD_2", "")
964 ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
965 "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2")
966 ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2",
967 "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2")
968 create_defect_type(ddb, 1)
969 create_defect_type(ddb, 3)
970 # assert primary and virtual defects are right
971 ids, names, m = ddb.get_channels()
972 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'
973 ids, names, m = ddb.get_virtual_channels()
974 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'
975
976@test()

◆ test_nonpresent()

python.tests.test_nonpresent ( )

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

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

◆ test_normalize_defect_names()

python.tests.test_normalize_defect_names ( )

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

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

◆ test_query_with_primary_dependencies()

python.tests.test_query_with_primary_dependencies ( )

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

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

◆ test_query_with_primary_dependencies_with_ignore()

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 743 of file DataQuality/DQDefects/python/tests/__init__.py.

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

◆ test_reject_duplicate_names()

python.tests.test_reject_duplicate_names ( )

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

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

◆ test_rename_defects()

python.tests.test_rename_defects ( )

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

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

◆ test_return_types()

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

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

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

◆ test_tagging_unicode()

python.tests.test_tagging_unicode ( )

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

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

◆ test_update_virtual_defect()

python.tests.test_update_virtual_defect ( )

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

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

◆ test_virtual_defect_consistency()

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

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

775def test_virtual_defect_consistency():
776 """
777 Checking that virtual flags don't depend on non-existent flags
778 """
779 DefectsDB()._virtual_defect_consistency_check()
780
781@test()

◆ test_virtual_defect_creation()

python.tests.test_virtual_defect_creation ( )

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

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

◆ test_virtual_defect_creation_unicode()

python.tests.test_virtual_defect_creation_unicode ( )

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

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

◆ test_virtual_defect_failure_nonascii_name()

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 329 of file DataQuality/DQDefects/python/tests/__init__.py.

329def test_virtual_defect_failure_nonascii_name():
330 """
331 Check that we raise an error if the virtual defect name is not ASCII
332 """
333 ddb = DefectsDB(TEST_DATABASE, read_only=False)
334
335 ddb.create_defect(u"DQD_TEST_DEFECT_0", "Test")
336 ddb.new_virtual_defect(u"DQD_TÉST_VIRTUAL_DÉFÉCT",
337 u"Comment", u"DQD_TEST_DEFECT_0")
338
339@test()

◆ test_virtual_defect_hiding()

python.tests.test_virtual_defect_hiding ( )

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

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

◆ test_virtual_defect_list_update_on_creation()

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 294 of file DataQuality/DQDefects/python/tests/__init__.py.

294def test_virtual_defect_list_update_on_creation():
295 """
296 Check that the virtual defect name list is updated when a defect is created
297 """
298 ddb = DefectsDB(TEST_DATABASE, read_only=False)
299 name = create_defect_type(ddb, 0)
300 ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT",
301 "Comment", name)
302
303 assert ddb.virtual_defect_names == set(["DQD_TEST_VIRTUAL_DEFECT"])
304
305@test()

◆ test_virtual_defects()

python.tests.test_virtual_defects ( )

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

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

◆ test_virtual_defects_deep()

python.tests.test_virtual_defects_deep ( )

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

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

◆ test_virtual_defects_invert()

python.tests.test_virtual_defects_invert ( )

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

109def test_virtual_defects_invert():
110 "Testing virtual defects involving inversion"
111 ddb = DefectsDB(TEST_DATABASE, read_only=False)
112
113 # Create two defects
114 create_defect_type(ddb, 0)
115 create_defect_type(ddb, 1)
116 create_defect_type(ddb, 2)
117
118 # Make a virtual defect whose result is the combination of the above
119 ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment",
120 "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 !DQD_TEST_DEFECT_2")
121
122 # Insert an iov into each
123 ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests")
124 ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests")
125 ddb.insert("DQD_TEST_DEFECT_2", 50, 125, "Test", "DQDefects.tests")
126
127 # See what the result of the virtual defect is
128 iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
129
130 # Tests against the value
131 assert len(iovs) == 4, list(iovs)
132 first, second, third, fourth = iovs
133 assert (first.since, first.until) == (0, 50), first
134 assert (second.since, second.until) == (50, 100), second
135 assert (third.since, third.until) == (125, 150), third
136 assert (fourth.since, fourth.until) == (150, 200), fourth
137 assert first.channel == second.channel == third.channel == fourth.channel == "DQD_TEST_VIRTUAL_DEFECT", (first.channel, second.channel, third.channel, fourth.channel)
138 del first, second, third, fourth, iovs
139
140 # Test evaluate_full=False
141 iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"], evaluate_full=False)
142 assert len(iovs) == 2, list(iovs)
143
144 # Now unset the present bit
145 ddb.insert("DQD_TEST_DEFECT_2", 50, 150, "Test", "DQDefects.tests", present=False)
146 iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"])
147
148 # here we are sensitive to details of python ordering ...
149 assert len(iovs) == 3, list(iovs)
150 first, second, third = iovs
151 assert (first.since, first.until) == (0, 100), first
152 assert (second.since, second.until) == (100, 150), second
153 assert (third.since, third.until) == (150, 200), third
154 assert first.channel == second.channel == third.channel == "DQD_TEST_VIRTUAL_DEFECT", (first.channel, second.channel, third.channel)
155 del first, second, third, iovs
156
157
158@test()

◆ test_virtual_defects_stress()

python.tests.test_virtual_defects_stress ( )

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

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

Variable Documentation

◆ log

python.tests.log

◆ teardown_db

python.tests.teardown_db = None

◆ TEST_DATABASE

str python.tests.TEST_DATABASE = "test_defects.db/COMP200"