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.

преди 1 година
преди 1 година
преди 1 година
преди 3 месеца
преди 3 месеца
преди 3 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import os
  2. import pytest
  3. from collections import OrderedDict
  4. os.environ["TESTING"] = "True"
  5. @pytest.fixture(scope='function')
  6. def StringDictionaries():
  7. ParamLine1 = OrderedDict({'parameter name1': 'value1'})
  8. ParamLine2 = OrderedDict({'parameter name2': 'value2'})
  9. ParamLine3 = OrderedDict({'parameter name3': 'value3'})
  10. Section1 = OrderedDict({'section name1': OrderedDict(**ParamLine1,
  11. **ParamLine2)})
  12. Section2 = OrderedDict({'section name2': OrderedDict(**ParamLine1,
  13. **ParamLine2)})
  14. Section3 = OrderedDict({'section name3': OrderedDict(**ParamLine3)})
  15. OriginalDictionary = OrderedDict(**Section1, **Section2)
  16. TemplateDictionary = OrderedDict(**Section3)
  17. ResultDictionary = OrderedDict(**Section1, **Section2, **Section3)
  18. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  19. @pytest.fixture(scope='function')
  20. def TupleDictionaries():
  21. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  22. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  23. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  24. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  25. **ParamLine2)})
  26. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  27. **ParamLine2)})
  28. Section3 = OrderedDict({('', 'section name3'): OrderedDict(**ParamLine3)})
  29. OriginalDictionary = OrderedDict(**Section1, **Section2)
  30. TemplateDictionary = OrderedDict(**Section3)
  31. ResultDictionary = OrderedDict(**Section1, **Section2, **Section3)
  32. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  33. @pytest.fixture(scope='function')
  34. def MergeSectionDictionaries():
  35. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  36. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  37. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  38. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  39. **ParamLine2)})
  40. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  41. **ParamLine2)})
  42. Section2Add = OrderedDict({('', 'section name2'):
  43. OrderedDict(**ParamLine3)})
  44. Section2Added = OrderedDict({('', 'section name2'):
  45. OrderedDict(**ParamLine1,
  46. **ParamLine2,
  47. **ParamLine3)})
  48. OriginalDictionary = OrderedDict(**Section1, **Section2)
  49. TemplateDictionary = OrderedDict(**Section2Add)
  50. ResultDictionary = OrderedDict(**Section1, **Section2Added)
  51. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  52. @pytest.fixture(scope='function')
  53. def ChangeParameterDictionaries():
  54. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  55. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  56. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  57. ParamLine2New = OrderedDict({('', 'parameter name2'): 'NewValue'})
  58. ParamLine3New = OrderedDict({('', 'parameter name3'): 'OtherValue'})
  59. Section = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  60. **ParamLine2,
  61. **ParamLine3)})
  62. SectionNew = OrderedDict({('', 'section name1'):
  63. OrderedDict(**ParamLine1,
  64. **ParamLine2New,
  65. **ParamLine3New)})
  66. OriginalDictionary = OrderedDict(**Section)
  67. TemplateDictionary = OrderedDict(**SectionNew)
  68. ResultDictionary = TemplateDictionary
  69. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  70. @pytest.fixture(scope='function')
  71. def DeleteSectionDictionaries():
  72. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  73. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  74. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  75. **ParamLine2)})
  76. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  77. **ParamLine2)})
  78. SectionDel = OrderedDict({('!', 'section name2'): OrderedDict()})
  79. OriginalDictionary = OrderedDict(**Section1, **Section2)
  80. TemplateDictionary = OrderedDict(**SectionDel)
  81. ResultDictionary = OrderedDict(**Section1)
  82. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  83. @pytest.fixture(scope='function')
  84. def ReplaceSectionDictionaries():
  85. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  86. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  87. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  88. ParamLine4 = OrderedDict({('', 'parameter name4'): 'value4'})
  89. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  90. **ParamLine2)})
  91. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  92. **ParamLine2)})
  93. Section2Replace = OrderedDict({('-', 'section name2'):
  94. OrderedDict(**ParamLine3, **ParamLine4)})
  95. Section2Replaced = OrderedDict({('', 'section name2'):
  96. OrderedDict(**ParamLine3, **ParamLine4)})
  97. OriginalDictionary = OrderedDict(**Section1, **Section2)
  98. TemplateDictionary = OrderedDict(**Section2Replace)
  99. ResultDictionary = OrderedDict(**Section1, **Section2Replaced)
  100. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  101. @pytest.fixture(scope='function')
  102. def DeleteParameterDictionaries():
  103. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  104. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  105. ParamLineDel = OrderedDict({('!', 'parameter name2'): 'value2'})
  106. Section1 = OrderedDict({('', 'section name1'): OrderedDict(**ParamLine1,
  107. **ParamLine2)})
  108. Section2 = OrderedDict({('', 'section name2'): OrderedDict(**ParamLine1,
  109. **ParamLine2)})
  110. SectionDel = OrderedDict({('', 'section name2'):
  111. OrderedDict(**ParamLineDel)})
  112. SectionAfterDel = OrderedDict({('', 'section name2'):
  113. OrderedDict(**ParamLine1)})
  114. OriginalDictionary = OrderedDict(**Section1, **Section2)
  115. TemplateDictionary = OrderedDict(**SectionDel)
  116. ResultDictionary = OrderedDict(**Section1, **SectionAfterDel)
  117. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  118. @pytest.fixture(scope='function')
  119. def DictionariesWithoutSections():
  120. ParamLine1 = OrderedDict({('', 'parameter name1'): 'value1'})
  121. ParamLine2 = OrderedDict({('', 'parameter name2'): 'value2'})
  122. ParamLine3 = OrderedDict({('', 'parameter name3'): 'value3'})
  123. ParamLineDel = OrderedDict({('!', 'parameter name2'): ''})
  124. OriginalDictionary = OrderedDict(**ParamLine1, **ParamLine2)
  125. TemplateDictionary = OrderedDict(**ParamLine3, **ParamLineDel)
  126. ResultDictionary = OrderedDict(**ParamLine1, **ParamLine3)
  127. return (OriginalDictionary, TemplateDictionary, ResultDictionary)
  128. def pytest_addoption(parser):
  129. parser.addoption(
  130. "--chroot-test",
  131. action="store_true",
  132. default=False,
  133. help="run chroot tests"
  134. )
  135. parser.addoption(
  136. "--backgrounds-slow",
  137. action="store_true",
  138. default=False,
  139. help="run slow backgrounds tests."
  140. )
  141. parser.addoption(
  142. "--from-root",
  143. action="store_true",
  144. default=False,
  145. help="run tests that needs root rights."
  146. )
  147. def pytest_collection_modifyitems(config, items):
  148. if not config.getoption("--chroot-test"):
  149. skip_chroot = pytest.mark.skip(
  150. reason="need --chroot-test option to run")
  151. for item in items:
  152. if "chroot" in item.keywords:
  153. item.add_marker(skip_chroot)
  154. if not config.getoption("--backgrounds-slow"):
  155. skip_backgrounds = pytest.mark.skip(
  156. reason="need --backgrounds-slow option to run")
  157. for item in items:
  158. if "backgrounds_slow" in item.keywords:
  159. item.add_marker(skip_backgrounds)
  160. if not config.getoption("--from-root"):
  161. skip_from_root = pytest.mark.skip(
  162. reason="need --from-root option to run")
  163. for item in items:
  164. if "needs_root" in item.keywords:
  165. item.add_marker(skip_from_root)