You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

icomponent.py 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Component interfaces."""
  16. class IComponent:
  17. """Component interfaces."""
  18. def __init__(self, verification_set):
  19. self.verification_set = verification_set
  20. def run(self):
  21. raise NotImplementedError
  22. def get_result(self):
  23. return self.result
  24. class IDataComponent(IComponent):
  25. """Create inputs for verification_set."""
  26. def run(self):
  27. self.result = self.create_inputs(self.verification_set)
  28. def create_inputs(self, verification_set):
  29. raise NotImplementedError
  30. class IBuilderComponent(IComponent):
  31. """Build system under test."""
  32. def run(self):
  33. self.result = self.build_sut(self.verification_set)
  34. def build_sut(self, verification_set):
  35. raise NotImplementedError
  36. class IExectorComponent(IComponent):
  37. """Execute sut, take (function, input) pairs as input."""
  38. def __init__(self, verification_set, function, inputs):
  39. super(IExectorComponent, self).__init__(verification_set)
  40. self.function = function
  41. self.inputs = inputs
  42. def run(self):
  43. self.result = self.run_function(self.function, self.inputs, self.verification_set)
  44. def run_function(self, function, inputs, verification_set):
  45. raise NotImplementedError
  46. class IVerifierComponent(IComponent):
  47. """Verify sut result, take (expect, result) pairs as input."""
  48. def __init__(self, verification_set, expect, result):
  49. super(IVerifierComponent, self).__init__(verification_set)
  50. self.expect = expect
  51. self.func_result = result
  52. def run(self):
  53. self.result = self.verify(self.expect, self.func_result, self.verification_set)
  54. def verify(self, expect, func_result, verification_set):
  55. raise NotImplementedError
  56. class IFIPolicyComponent(IComponent):
  57. """Combine functions/inputs."""
  58. def __init__(self, verification_set, function, inputs):
  59. super(IFIPolicyComponent, self).__init__(verification_set)
  60. self.function = function
  61. self.inputs = inputs
  62. def run(self):
  63. self.result = self.combine(self.function, self.inputs, self.verification_set)
  64. def combine(self, function, inputs, verification_set):
  65. raise NotImplementedError
  66. class IERPolicyComponent(IComponent):
  67. """Combine expects and results."""
  68. def __init__(self, verification_set, expect, result):
  69. super(IERPolicyComponent, self).__init__(verification_set)
  70. self.expect = expect
  71. self.result = result
  72. def run(self):
  73. self.result = self.combine(self.expect, self.result, self.verification_set)
  74. def combine(self, expect, result, verification_set):
  75. raise NotImplementedError
  76. class IFacadeComponent(IComponent):
  77. """Adapt verification_set."""
  78. def run(self):
  79. self.result = self.adapt(self.verification_set)
  80. def adapt(self, verification_set):
  81. raise NotImplementedError