opentf-toolkit-nightly 0.57.0.dev1057__py3-none-any.whl → 0.57.0.dev1071__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
 
15
15
  """Datasources (testcases, tags and jobs) retrieval helpers"""
16
16
 
17
- from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
17
+ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
18
18
 
19
19
  from datetime import datetime
20
20
 
@@ -22,6 +22,7 @@ from datetime import datetime
22
22
  from flask import current_app
23
23
 
24
24
  from opentf.commons.expressions import evaluate_bool
25
+ from opentf.commons.selectors import match_selectors
25
26
 
26
27
 
27
28
  ########################################################################
@@ -99,9 +100,11 @@ def parse_testcase_name(full_name: str) -> Tuple[str, str]:
99
100
  ## Datasource: Testcases
100
101
 
101
102
 
102
- def in_scope(expr: str, contexts: Dict[str, Any]) -> bool:
103
+ def in_scope(expr: Union[str, bool], contexts: Dict[str, Any]) -> bool:
103
104
  """Safely evaluate datasource scope."""
104
105
  try:
106
+ if isinstance(expr, bool):
107
+ return expr
105
108
  return evaluate_bool(expr, contexts)
106
109
  except ValueError as err:
107
110
  raise ValueError(f'Invalid conditional {expr}: {err}.')
@@ -399,9 +402,7 @@ def _get_testresult_labels(
399
402
 
400
403
 
401
404
  def _make_testcase_from_testresult(
402
- item: Dict[str, Any],
403
- labels: Dict[str, Any],
404
- scope: str,
405
+ item: Dict[str, Any], labels: Dict[str, Any], scope: Union[str, bool]
405
406
  ) -> Dict[str, Any]:
406
407
  suite_name, testcase_name = parse_testcase_name(item['name'])
407
408
  item_data = {
@@ -434,8 +435,55 @@ def _make_testcase_from_testresult(
434
435
  return testcase
435
436
 
436
437
 
438
+ def _get_max_count(state: Dict[str, Any]) -> int:
439
+ if state['reset']:
440
+ return state['per_page'] * state['page']
441
+ return state['per_page']
442
+
443
+
444
+ def _extract_testcases(
445
+ testresults: List[Dict[str, Any]],
446
+ state: Dict[str, Any],
447
+ scope: Union[str, bool],
448
+ events: List[Dict[str, Any]],
449
+ ) -> Dict[str, Dict[str, Any]]:
450
+ testcases = {}
451
+ items = 0
452
+ for i, testresult in enumerate(
453
+ testresults[state['last_notification_used'] :],
454
+ start=state['last_notification_used'],
455
+ ):
456
+ if i == state['last_notification_used']:
457
+ last_testresult_used = state['last_testresult_used']
458
+ else:
459
+ last_testresult_used = 0
460
+ execution_id = testresult['metadata']['attachment_origin'][0]
461
+ labels = _get_testresult_labels(execution_id, events)
462
+ if not labels:
463
+ continue
464
+ for j, item in enumerate(
465
+ testresult['spec']['testResults'][last_testresult_used:],
466
+ start=last_testresult_used,
467
+ ):
468
+ testcase = _make_testcase_from_testresult(item, labels, scope)
469
+ if not testcase:
470
+ continue
471
+ if not match_selectors(testcase, state['fieldselector']):
472
+ continue
473
+ testcases[item['id']] = testcase
474
+ items += 1
475
+ if items > _get_max_count(state):
476
+ state['last_notification_used'] = i
477
+ state['last_testresult_used'] = j
478
+ return testcases
479
+
480
+ state['last_notification_used'] = i + 1
481
+ state['last_testresult_used'] = 0
482
+ return testcases
483
+
484
+
437
485
  def get_testcases(
438
- events: List[Dict[str, Any]], scope: str = 'true'
486
+ events: List[Dict[str, Any]], scope: Union[str, bool] = True, state=None
439
487
  ) -> Dict[str, Dict[str, Any]]:
440
488
  """Extract metadata for each test result.
441
489
 
@@ -489,6 +537,9 @@ def get_testcases(
489
537
  A _ValueError_ exception is raised if there were no test results in
490
538
  `events` or some scope errors occured retrieving test results.
491
539
  """
540
+ if not state:
541
+ raise ValueError('No workflow cache state received from observer.')
542
+
492
543
  if _uses_inception(events):
493
544
  testresults = _get_inception_testresults(events)
494
545
  else:
@@ -497,17 +548,10 @@ def get_testcases(
497
548
  if not testresults:
498
549
  raise ValueError('No test results in events.')
499
550
 
500
- testcases = {}
501
- for testresult in testresults:
502
- execution_id = testresult['metadata']['attachment_origin'][0]
503
- labels = _get_testresult_labels(execution_id, events)
504
- if not labels:
505
- continue
506
- for item in testresult['spec']['testResults']:
507
- if testcase := _make_testcase_from_testresult(item, labels, scope):
508
- testcases[item['id']] = testcase
551
+ testcases = _extract_testcases(testresults, state, scope, events)
509
552
  if not testcases:
510
553
  raise ValueError(f'No test cases matching scope `{scope}`.')
554
+
511
555
  return testcases
512
556
 
513
557
 
@@ -538,7 +582,9 @@ def _make_tag_datasource(tag: str, parent: Dict[str, Any]) -> Dict[str, Any]:
538
582
  }
539
583
 
540
584
 
541
- def get_tags(events: List[Dict[str, Any]], scope: str = 'true') -> Dict[str, Any]:
585
+ def get_tags(
586
+ events: List[Dict[str, Any]], scope: Union[str, bool] = True, state=None
587
+ ) -> Dict[str, Any]:
542
588
  """Extract metadata for each execution environment tag.
543
589
 
544
590
  # Required parameters:
@@ -574,7 +620,7 @@ def get_tags(events: List[Dict[str, Any]], scope: str = 'true') -> Dict[str, Any
574
620
  'No job events found in workflow. Cannot extract data for tags.'
575
621
  )
576
622
  try:
577
- testcases = get_testcases(events, scope)
623
+ testcases = get_testcases(events, scope, state)
578
624
  except ValueError as err:
579
625
  if str(err).startswith('[SCOPE ERROR] '):
580
626
  raise ValueError(str(err))
@@ -711,7 +757,9 @@ def _make_job_datasource(
711
757
  }
712
758
 
713
759
 
714
- def get_jobs(events: List[Dict[str, Any]], scope: str = 'true') -> Dict[str, Any]:
760
+ def get_jobs(
761
+ events: List[Dict[str, Any]], scope: Union[str, bool] = True, state=None
762
+ ) -> Dict[str, Any]:
715
763
  """Extract metadata for each job.
716
764
 
717
765
  # Required parameters:
@@ -764,7 +812,7 @@ def get_jobs(events: List[Dict[str, Any]], scope: str = 'true') -> Dict[str, Any
764
812
  )
765
813
 
766
814
  try:
767
- testcases = get_testcases(events, scope)
815
+ testcases = get_testcases(events, scope, state)
768
816
  except ValueError as err:
769
817
  if str(err).startswith('[SCOPE ERROR] '):
770
818
  raise ValueError(str(err))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.57.0.dev1057
3
+ Version: 0.57.0.dev1071
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -1,7 +1,7 @@
1
1
  opentf/commons/__init__.py,sha256=Uq-7WvkMoBiF3C1KnhwIL4LCKpT8EvomnuG4MBYpIhs,21994
2
2
  opentf/commons/auth.py,sha256=bM2Z3kxm2Wku1lKXaRAIg37LHvXWAXIZIqjplDfN2P8,15899
3
3
  opentf/commons/config.py,sha256=dyus4K5Zdmcftc3Y9Z1YRkzA1KwiRLHoeAlg2_A49QM,7876
4
- opentf/commons/datasources.py,sha256=4ye-TMtaE88O8GVcWx-FtKXOC8aIZLteR6wfIr7Do8U,25232
4
+ opentf/commons/datasources.py,sha256=LjIjZbf08u1VllPN4fDss0OAg-_7gtRqgpIZ2tLuiHo,26807
5
5
  opentf/commons/expressions.py,sha256=jM_YKXVOFhvOE2aE2IuacuvxhIsOYTFs2oQkpcbWR6g,19645
6
6
  opentf/commons/pubsub.py,sha256=DVrSara5FRfNdPBwXKUkTobqGki0RPDehylTEFcJnFc,7341
7
7
  opentf/commons/schemas.py,sha256=YSCvlmqc7satt-OqIoYXnmhOyo9h8wIpNyKaBAY4u9c,4039
@@ -49,8 +49,8 @@ opentf/scripts/startup.py,sha256=Da2zo93pBWbdRmj-wgekgLcF94rpNc3ZkbvR8R0w8XY,212
49
49
  opentf/toolkit/__init__.py,sha256=4UbExlqRO8Ew7GYRrMdEDruMIB0zTLSsoVCKfW3vPnQ,23488
50
50
  opentf/toolkit/channels.py,sha256=6xcVKHUK2FdyVKIQmPQbakngfVuQDzCcD_lInOdKpro,17171
51
51
  opentf/toolkit/core.py,sha256=GdmEJ0ikdMdpViEpR4jP-viqfvBUHnpiFCOXwLGThxg,9606
52
- opentf_toolkit_nightly-0.57.0.dev1057.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
- opentf_toolkit_nightly-0.57.0.dev1057.dist-info/METADATA,sha256=Rfyt1TuD1vqvhdTcSAs1G_3Iujzd6P8StHAFXiE9dYo,1943
54
- opentf_toolkit_nightly-0.57.0.dev1057.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
55
- opentf_toolkit_nightly-0.57.0.dev1057.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
56
- opentf_toolkit_nightly-0.57.0.dev1057.dist-info/RECORD,,
52
+ opentf_toolkit_nightly-0.57.0.dev1071.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
+ opentf_toolkit_nightly-0.57.0.dev1071.dist-info/METADATA,sha256=C46QttPC75AZio20HOPCH_uxLwdUoKhC-jNIIFKfgP4,1943
54
+ opentf_toolkit_nightly-0.57.0.dev1071.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
55
+ opentf_toolkit_nightly-0.57.0.dev1071.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
56
+ opentf_toolkit_nightly-0.57.0.dev1071.dist-info/RECORD,,