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

181 lines
8.0 KiB

  1. import pytest
  2. from collections import OrderedDict
  3. @pytest.fixture(scope='function')
  4. def StringDictionaries():
  5. ParamLine1 = OrderedDict({'parameter name1': 'value1'})
  6. ParamLine2 = OrderedDict({'parameter name2': 'value2'})
  7. ParamLine3 = OrderedDict({'parameter name3': 'value3'})
  8. Section1 = OrderedDict({'section name1': OrderedDict(**ParamLine1,
  9. **ParamLine2)})
  10. Section2 = OrderedDict({'section name2': OrderedDict(**ParamLine1,
  11. **ParamLine2)})
  12. Section3 = OrderedDict({'section name3': OrderedDict(**ParamLine3)})
  13. OriginalDictionary = OrderedDict(**Section1, **Section2)
  14. TemplateDictionary = OrderedDict(**Section3)
  15. ResultDictionary = OrderedDict(**Section1, **Section2, **Section3)
  16. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  17. @pytest.fixture(scope='function')
  18. def TupleDictionaries():
  19. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  20. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  21. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  22. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  23. **ParamLine2)})
  24. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  25. **ParamLine2)})
  26. Section3 = OrderedDict({('', 'section name3'): OrderedDict(**ParamLine3)})
  27. OriginalDictionary = OrderedDict(**Section1, **Section2)
  28. TemplateDictionary = OrderedDict(**Section3)
  29. ResultDictionary = OrderedDict(**Section1, **Section2, **Section3)
  30. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  31. @pytest.fixture(scope='function')
  32. def MergeSectionDictionaries():
  33. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  34. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  35. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  36. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  37. **ParamLine2)})
  38. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  39. **ParamLine2)})
  40. Section2Add = OrderedDict({('', 'section name2'):
  41. OrderedDict(**ParamLine3)})
  42. Section2Added = OrderedDict({('', 'section name2'):
  43. OrderedDict(**ParamLine1,
  44. **ParamLine2,
  45. **ParamLine3)})
  46. OriginalDictionary = OrderedDict(**Section1, **Section2)
  47. TemplateDictionary = OrderedDict(**Section2Add)
  48. ResultDictionary = OrderedDict(**Section1, **Section2Added)
  49. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  50. @pytest.fixture(scope='function')
  51. def ChangeParameterDictionaries():
  52. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  53. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  54. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  55. ParamLine2New = OrderedDict({('', 'parameter name2'): 'NewValue'})
  56. ParamLine3New = OrderedDict({('', 'parameter name3'): 'OtherValue'})
  57. Section = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  58. **ParamLine2,
  59. **ParamLine3)})
  60. SectionNew = OrderedDict({('', 'section name1'):
  61. OrderedDict(**ParamLine1,
  62. **ParamLine2New,
  63. **ParamLine3New)})
  64. OriginalDictionary = OrderedDict(**Section)
  65. TemplateDictionary = OrderedDict(**SectionNew)
  66. ResultDictionary = TemplateDictionary
  67. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  68. @pytest.fixture(scope='function')
  69. def DeleteSectionDictionaries():
  70. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  71. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  72. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  73. **ParamLine2)})
  74. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  75. **ParamLine2)})
  76. SectionDel = OrderedDict({('!', 'section name2'): OrderedDict()})
  77. OriginalDictionary = OrderedDict(**Section1, **Section2)
  78. TemplateDictionary = OrderedDict(**SectionDel)
  79. ResultDictionary = OrderedDict(**Section1)
  80. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  81. @pytest.fixture(scope='function')
  82. def ReplaceSectionDictionaries():
  83. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  84. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  85. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  86. ParamLine4 = OrderedDict({('', 'parameter name4'): 'value4'})
  87. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  88. **ParamLine2)})
  89. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  90. **ParamLine2)})
  91. Section2Replace = OrderedDict({('-', 'section name2'):
  92. OrderedDict(**ParamLine3, **ParamLine4)})
  93. Section2Replaced = OrderedDict({('', 'section name2'):
  94. OrderedDict(**ParamLine3, **ParamLine4)})
  95. OriginalDictionary = OrderedDict(**Section1, **Section2)
  96. TemplateDictionary = OrderedDict(**Section2Replace)
  97. ResultDictionary = OrderedDict(**Section1, **Section2Replaced)
  98. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  99. @pytest.fixture(scope='function')
  100. def DeleteParameterDictionaries():
  101. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  102. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  103. ParamLineDel = OrderedDict({('!', 'parameter name2'): 'value2'})
  104. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  105. **ParamLine2)})
  106. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  107. **ParamLine2)})
  108. SectionDel = OrderedDict({('', 'section name2'):
  109. OrderedDict(**ParamLineDel)})
  110. SectionAfterDel = OrderedDict({('', 'section name2'):
  111. OrderedDict(**ParamLine1)})
  112. OriginalDictionary = OrderedDict(**Section1, **Section2)
  113. TemplateDictionary = OrderedDict(**SectionDel)
  114. ResultDictionary = OrderedDict(**Section1, **SectionAfterDel)
  115. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  116. @pytest.fixture(scope='function')
  117. def DictionariesWithoutSections():
  118. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  119. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  120. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  121. ParamLineDel = OrderedDict({('!', 'parameter name2'): ''})
  122. OriginalDictionary = OrderedDict(**ParamLine1, **ParamLine2)
  123. TemplateDictionary = OrderedDict(**ParamLine3, **ParamLineDel)
  124. ResultDictionary = OrderedDict(**ParamLine1, **ParamLine3)
  125. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  126. import pytest
  127. def pytest_addoption(parser):
  128. parser.addoption(
  129. "--chroot-test", action="store_true", default=False, help="run chroot tests"
  130. )
  131. def pytest_collection_modifyitems(config, items):
  132. if config.getoption("--chroot-test"):
  133. return
  134. skip_chroot = pytest.mark.skip(reason="need --chroot option to run")
  135. for item in items:
  136. if "chroot" in item.keywords:
  137. item.add_marker(skip_chroot)