@@ -217,6 +217,23 @@ def query_str(self, pattern_string):
217
217
kcidb .orm .Pattern .parse (pattern_string )
218
218
)
219
219
220
+ @staticmethod
221
+ def filter_valid (container ):
222
+ """
223
+ Filter out the valid items in a container.
224
+ Args:
225
+ container: A list whose items are object(s) that
226
+ have "valid" property.
227
+
228
+ Returns:
229
+ The list of object(s) with valid property true.
230
+ """
231
+ assert all (hasattr (i , "valid" ) for i in container )
232
+ return list (filter (
233
+ lambda item : item .valid is True ,
234
+ container
235
+ ))
236
+
220
237
def assertContains (self , container , contents ):
221
238
"""
222
239
Check that a container has the specified contents.
@@ -456,3 +473,81 @@ def test_traversing_revision_links(self):
456
473
self .assertFalse (revision .builds_valid )
457
474
458
475
self .assertIsInstance (revision .tests_root , Node )
476
+
477
+ def test_traversing_valid_checkout_links (self ):
478
+ """Check that valid checkout links are successfully traversed."""
479
+ checkouts = KCIDBTraversingTestCase .filter_valid (
480
+ self .query_str (
481
+ '>revision["5acb9c2a7bc836e9e5172bbcd2311499c5b4e5f1", ""]'
482
+ '>checkout#'
483
+ )["checkout" ]
484
+ )
485
+ self .assertContains (checkouts , (Checkout , 2 ))
486
+ self .assertEqual (
487
+ checkouts [0 ].get_parent_id ("revision" ),
488
+ checkouts [0 ].revision .get_id ()
489
+ )
490
+ self .assertContains (checkouts [0 ].builds , (Build , 3 ))
491
+ self .assertContains (checkouts [0 ].tests , (Test , 6 ))
492
+ self .assertIsInstance (checkouts [0 ].tests_root , Node )
493
+
494
+ def test_traversing_valid_build_links (self ):
495
+ """Check that valid build links are successfully traversed."""
496
+ builds = KCIDBTraversingTestCase .filter_valid (
497
+ self .query_str (
498
+ '>revision["5acb9c2a7bc836e9e5172bbcd2311499c5b4e5f1", ""]'
499
+ '>checkout>build#'
500
+ )["build" ]
501
+ )
502
+ self .assertContains (builds , (Build , 4 ))
503
+ self .assertEqual (
504
+ builds [3 ].get_parent_id ("checkout" ),
505
+ builds [3 ].checkout .get_id ()
506
+ )
507
+ self .assertContains (builds [0 ].tests , (Test , 3 ))
508
+ self .assertIsInstance (builds [0 ].tests_root , Node )
509
+
510
+ def test_traversing_test_links (self ):
511
+ """Check that test links are successfully traversed."""
512
+ tests = self .query_str (
513
+ '>revision["5acb9c2a7bc836e9e5172bbcd2311499c5b4e5f1", ""]'
514
+ '>checkout>build>test#'
515
+ )["test" ]
516
+ self .assertContains (tests , (Test , 12 ))
517
+ self .assertEqual (
518
+ tests [2 ].get_parent_id ("build" ),
519
+ tests [2 ].build .get_id ()
520
+ )
521
+
522
+ def test_traversing_revision_root_test_node (self ):
523
+ """
524
+ Check that valid revision's root test node links are
525
+ successfully traversed.
526
+ """
527
+ revision = self .query_str (
528
+ '>revision["5acb9c2a7bc836e9e5172bbcd2311499c5b4e5f1", ""]#'
529
+ )['revision' ][0 ]
530
+
531
+ self .assertEqual (
532
+ revision ,
533
+ revision .tests_root .parent
534
+ )
535
+ self .assertContains (
536
+ revision .tests_root .tests ,
537
+ (Test , 12 )
538
+ )
539
+
540
+ path = []
541
+ for key in revision .tests_root .nodes :
542
+ node = revision .tests_root .nodes [key ]
543
+ path .append (node .path )
544
+
545
+ self .assertEqual (node .parent , revision .tests_root )
546
+
547
+ self .assertContains (node .tests , (Test , 4 ))
548
+ # Check that each tests have the same path.
549
+ self .assertEqual (len ({obj .path for obj in node .tests }), 1 )
550
+
551
+ self .assertEqual (node .nodes , {})
552
+
553
+ self .assertEqual (path , ["pass1" , "pass2" , "fail" ])
0 commit comments