|
18 | 18 | from pytest import MonkeyPatch |
19 | 19 | import wx |
20 | 20 | from utest.resources.datafilereader import DATAPATH |
| 21 | +from robotide.context import SETTINGS_DIRECTORY |
21 | 22 |
|
22 | 23 | TEST_PROJECT = os.path.join(DATAPATH, 'test_project') |
| 24 | +PROJECT_EMPTY_PROJECT_SETTINGS = os.path.join(TEST_PROJECT, 'empty_project_settings') |
| 25 | +PROJECT_EMPTY_PROJECT_SETTINGS_TEST= os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, 'minimal.robot') |
| 26 | +PROJECT_NO_PROJECT_SETTINGS = os.path.join(TEST_PROJECT, 'no_project_settings') |
| 27 | +PROJECT_NO_PROJECT_SETTINGS_TEST= os.path.join(PROJECT_NO_PROJECT_SETTINGS, 'minimal.robot') |
| 28 | +SUBPROJECT_WITH_PROJECT_SETTINGS_ONE = os.path.join(TEST_PROJECT, 'with_project_settings_one') |
| 29 | +SUBPROJECT_WITH_PROJECT_SETTINGS_ONE_TEST= os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS_ONE, 'minimal.robot') |
| 30 | +SUBPROJECT_PROJECT_SETTINGS_TWO = os.path.join(TEST_PROJECT, 'with_project_settings_two') |
| 31 | +SUBPROJECT_PROJECT_SETTINGS_TWO_TEST= os.path.join(SUBPROJECT_PROJECT_SETTINGS_TWO, 'minimal.robot') |
| 32 | +SUBPROJECT_EMPTY_PROJECT_SETTINGS = os.path.join(TEST_PROJECT, 'with_project_settings_two', |
| 33 | + 'subproject_empty_project_settings') |
| 34 | +SUBPROJECT_EMPTY_PROJECT_SETTINGS_TEST= os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, 'minimal.robot') |
| 35 | +SUBPROJECT_NO_PROJECT_SETTINGS = os.path.join(TEST_PROJECT, 'with_project_settings_two', |
| 36 | + 'subproject_no_project_settings') |
| 37 | +SUBPROJECT_NO_PROJECT_SETTINGS_TEST= os.path.join(SUBPROJECT_NO_PROJECT_SETTINGS, 'minimal.robot') |
23 | 38 | SUBPROJECT_WITH_PROJECT_SETTINGS = os.path.join(TEST_PROJECT, 'with_project_settings_two', |
24 | 39 | 'subproject_with_project_settings') |
25 | 40 | SUBPROJECT_WITH_PROJECT_SETTINGS_TEST= os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS, 'minimal.robot') |
26 | 41 |
|
| 42 | +""" |
| 43 | +. |
| 44 | +├── empty_project_settings |
| 45 | +│ ├── minimal.robot |
| 46 | +│ └── .robot |
| 47 | +│ └── .gitkeep |
| 48 | +├── no_project_settings |
| 49 | +│ └── minimal.robot |
| 50 | +├── with_project_settings_one |
| 51 | +│ ├── minimal.robot |
| 52 | +│ └── .robot |
| 53 | +│ └── ride_settings.cfg |
| 54 | +└── with_project_settings_two |
| 55 | + ├── minimal.robot |
| 56 | + ├── .robot |
| 57 | + │ └── ride_settings.cfg |
| 58 | + ├── subproject_empty_project_settings |
| 59 | + │ ├── minimal.robot |
| 60 | + │ └── .robot |
| 61 | + │ └── .gitkeep |
| 62 | + ├── subproject_no_project_settings |
| 63 | + │ └── minimal.robot |
| 64 | + └── subproject_with_project_settings |
| 65 | + ├── minimal.robot |
| 66 | + └── .robot |
| 67 | + └── ride_settings.cfg |
| 68 | +""" |
| 69 | + |
27 | 70 |
|
28 | 71 | class TestProjectSettings(unittest.TestCase): |
29 | 72 |
|
30 | 73 | def setUp(self): |
| 74 | + if os.path.isfile(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')): |
| 75 | + os.remove(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 76 | + if os.path.isfile(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')): |
| 77 | + os.remove(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 78 | + |
| 79 | + def _setUp(self): |
31 | 80 | from robotide.application import RIDE |
32 | 81 | self.main_app = RIDE() |
33 | 82 | self.settings = self.main_app.settings |
34 | 83 | self.frame = self.main_app.frame |
35 | | - self.main_app.SetExitOnFrameDelete(True) |
| 84 | + # self.main_app.SetExitOnFrameDelete(True) |
36 | 85 |
|
37 | | - def tearDown(self): |
| 86 | + def _tearDown(self): |
38 | 87 | # builtins.__import__ = real_import |
| 88 | + # self.frame.Close(True) |
39 | 89 | self.main_app.ExitMainLoop() |
40 | 90 | self.main_app.Destroy() |
41 | 91 | self.main_app = None |
| 92 | + if os.path.isfile(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')): |
| 93 | + os.remove(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 94 | + if os.path.isfile(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')): |
| 95 | + os.remove(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 96 | + |
| 97 | + def test_project_empty_init_one(self): |
| 98 | + """ Empty projects create a settings file """ |
| 99 | + import robotide.application |
| 100 | + import wx |
| 101 | + |
| 102 | + from robotide.application import RIDE |
| 103 | + |
| 104 | + with MonkeyPatch().context() as ctx: |
| 105 | + myapp = wx.App(None) |
| 106 | + |
| 107 | + class SideEffect(RIDE): |
| 108 | + |
| 109 | + def __init__(self): |
| 110 | + self.frame = wx.Frame(None) |
| 111 | + self.settings_path = os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
| 112 | + |
| 113 | + def OnInit(self): # Overrides wx method |
| 114 | + pass |
| 115 | + |
| 116 | + def MainLoop(self): # Overrides wx method |
| 117 | + pass |
| 118 | + |
| 119 | + with MonkeyPatch().context() as m: |
| 120 | + m.setattr(robotide.application, 'RIDE', SideEffect) |
| 121 | + self._setUp() |
| 122 | + assert os.path.isdir(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot')) |
| 123 | + assert not os.path.exists(os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 124 | + settings_file = self.main_app.initialize_project_settings(PROJECT_EMPTY_PROJECT_SETTINGS_TEST) |
| 125 | + assert settings_file == os.path.join(PROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg') |
| 126 | + |
| 127 | + def test_project_empty_init_two(self): |
| 128 | + """ Empty projects create a settings file """ |
| 129 | + import robotide.application |
| 130 | + import wx |
| 131 | + |
| 132 | + from robotide.application import RIDE |
| 133 | + |
| 134 | + with MonkeyPatch().context() as ctx: |
| 135 | + myapp = wx.App(None) |
| 136 | + |
| 137 | + class SideEffect(RIDE): |
| 138 | + |
| 139 | + def __init__(self): |
| 140 | + self.frame = wx.Frame(None) |
| 141 | + self.settings_path = os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
| 142 | + |
| 143 | + def OnInit(self): # Overrides wx method |
| 144 | + pass |
| 145 | + |
| 146 | + def MainLoop(self): # Overrides wx method |
| 147 | + pass |
| 148 | + |
| 149 | + with MonkeyPatch().context() as m: |
| 150 | + m.setattr(robotide.application, 'RIDE', SideEffect) |
| 151 | + self._setUp() |
| 152 | + assert os.path.isdir(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot')) |
| 153 | + assert not os.path.exists(os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 154 | + settings_file = self.main_app.initialize_project_settings(SUBPROJECT_EMPTY_PROJECT_SETTINGS_TEST) |
| 155 | + assert settings_file == os.path.join(SUBPROJECT_EMPTY_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg') |
| 156 | + |
| 157 | + |
| 158 | + def test_project_no_init(self): |
| 159 | + """ No projects don't create a settings file, and use default settings or project above """ |
| 160 | + import robotide.application |
| 161 | + import wx |
| 162 | + |
| 163 | + from robotide.application import RIDE |
| 164 | + |
| 165 | + with MonkeyPatch().context() as ctx: |
| 166 | + myapp = wx.App(None) |
| 167 | + |
| 168 | + class SideEffect(RIDE): |
| 169 | + |
| 170 | + def __init__(self): |
| 171 | + self.frame = wx.Frame(None) |
| 172 | + self.settings_path = os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
| 173 | + |
| 174 | + def OnInit(self): # Overrides wx method |
| 175 | + pass |
| 176 | + |
| 177 | + def MainLoop(self): # Overrides wx method |
| 178 | + pass |
| 179 | + |
| 180 | + with MonkeyPatch().context() as m: |
| 181 | + m.setattr(robotide.application, 'RIDE', SideEffect) |
| 182 | + self._setUp() |
| 183 | + assert not os.path.exists(os.path.join(PROJECT_NO_PROJECT_SETTINGS, '.robot')) |
| 184 | + settings_file = self.main_app.initialize_project_settings(PROJECT_NO_PROJECT_SETTINGS_TEST) |
| 185 | + # print(f"DEBUG: PROJECT_NO_PROJECT_SETTINGS settings=={settings_file}") |
| 186 | + assert settings_file == os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
| 187 | + # assert settings_file == os.path.join(PROJECT_NO_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg') |
| 188 | + assert not os.path.exists(os.path.join(SUBPROJECT_NO_PROJECT_SETTINGS, '.robot')) |
| 189 | + settings_file = self.main_app.initialize_project_settings(SUBPROJECT_NO_PROJECT_SETTINGS_TEST) |
| 190 | + # print(f"DEBUG: SUBPROJECT_NO_PROJECT_SETTINGS settings=={settings_file}") |
| 191 | + assert settings_file == os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
42 | 192 |
|
43 | 193 | def test_project_init(self): |
44 | | - settings_file = self.main_app.initialize_project_settings(SUBPROJECT_WITH_PROJECT_SETTINGS) |
45 | | - assert settings_file == os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg') |
| 194 | + """ Projects use its settings file """ |
| 195 | + import robotide.application |
| 196 | + import wx |
| 197 | + |
| 198 | + from robotide.application import RIDE |
| 199 | + |
| 200 | + with MonkeyPatch().context() as ctx: |
| 201 | + myapp = wx.App(None) |
| 202 | + |
| 203 | + class SideEffect(RIDE): |
| 204 | + |
| 205 | + def __init__(self): |
| 206 | + self.frame = wx.Frame(None) |
| 207 | + self.settings_path = os.path.join(SETTINGS_DIRECTORY, 'settings.cfg') |
| 208 | + |
| 209 | + def OnInit(self): # Overrides wx method |
| 210 | + pass |
| 211 | + |
| 212 | + def MainLoop(self): # Overrides wx method |
| 213 | + pass |
| 214 | + |
| 215 | + with MonkeyPatch().context() as m: |
| 216 | + m.setattr(robotide.application, 'RIDE', SideEffect) |
| 217 | + self._setUp() |
| 218 | + assert os.path.exists(os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS_ONE, '.robot', 'ride_settings.cfg')) |
| 219 | + settings_file = self.main_app.initialize_project_settings(SUBPROJECT_WITH_PROJECT_SETTINGS_ONE_TEST) |
| 220 | + assert settings_file == os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS_ONE, '.robot', 'ride_settings.cfg') |
| 221 | + |
| 222 | + assert os.path.exists(os.path.join(SUBPROJECT_PROJECT_SETTINGS_TWO, '.robot', 'ride_settings.cfg')) |
| 223 | + settings_file = self.main_app.initialize_project_settings(SUBPROJECT_PROJECT_SETTINGS_TWO_TEST) |
| 224 | + assert settings_file == os.path.join(SUBPROJECT_PROJECT_SETTINGS_TWO, '.robot', 'ride_settings.cfg') |
| 225 | + |
| 226 | + assert os.path.exists(os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg')) |
| 227 | + settings_file = self.main_app.initialize_project_settings(SUBPROJECT_WITH_PROJECT_SETTINGS_TEST) |
| 228 | + assert settings_file == os.path.join(SUBPROJECT_WITH_PROJECT_SETTINGS, '.robot', 'ride_settings.cfg') |
46 | 229 |
|
47 | 230 |
|
48 | 231 | if __name__ == '__main__': |
|
0 commit comments