8
8
from collections import OrderedDict
9
9
from importlib import import_module
10
10
from types import ModuleType
11
+ from pathlib import Path
11
12
12
13
from zulip_botserver import server
13
14
from zulip_botserver .input_parameters import parse_args
@@ -214,13 +215,13 @@ def test_load_lib_modules(self) -> None:
214
215
# restructure zulip_bots, this test would fail and we would also update Botserver
215
216
# at the same time.
216
217
helloworld = import_module ('zulip_bots.bots.{bot}.{bot}' .format (bot = 'helloworld' ))
217
- root_dir = os . path . normpath ( os . path . join ( os . path . dirname ( os . path . abspath ( __file__ )), '../../' ) )
218
+ root_dir = Path ( __file__ ). parents [ 2 ]. as_posix ( )
218
219
# load valid module name
219
220
module = server .load_lib_modules (['helloworld' ])['helloworld' ]
220
221
assert module == helloworld
221
222
222
223
# load valid file path
223
- path = os . path . join (root_dir , 'zulip_bots/zulip_bots/bots/{bot}/{bot}.py' .format (bot = 'helloworld' ))
224
+ path = Path (root_dir , 'zulip_bots/zulip_bots/bots/{bot}/{bot}.py' .format (bot = 'helloworld' )). as_posix ( )
224
225
module = server .load_lib_modules ([path ])[path ]
225
226
assert module .__name__ == 'custom_bot_module'
226
227
assert module .__file__ == path
@@ -236,7 +237,7 @@ def test_load_lib_modules(self) -> None:
236
237
with self .assertRaisesRegexp (SystemExit , # type: ignore
237
238
'Error: Bot "{}/zulip_bots/zulip_bots/bots/helloworld.py" doesn\' t exist. '
238
239
'Please make sure you have set up the botserverrc file correctly.' .format (root_dir )):
239
- path = os . path . join (root_dir , 'zulip_bots/zulip_bots/bots/{bot}.py' .format (bot = 'helloworld' ))
240
+ path = Path (root_dir , 'zulip_bots/zulip_bots/bots/{bot}.py' .format (bot = 'helloworld' )). as_posix ( )
240
241
module = server .load_lib_modules ([path ])[path ]
241
242
242
243
if __name__ == '__main__' :
0 commit comments