zulip / python-zulip-api

Python library for the Zulip API.
https://zulip.com/api/
Apache License 2.0
350 stars 356 forks source link

Fix tests failing on Windows. #652

Closed ganpa3 closed 3 years ago

ganpa3 commented 3 years ago

Tests were failing on Windows since paths are case-insensitive on it. This uses pathlib library to compare paths on all platforms.

Fixes #651

Upasanadhameliya commented 3 years ago

@ganpa3 Its not completely fixed

(zulip-api-py3-venv) (zulipenv) S:\Sandy\Documents\College\Practice\Git\python-zulip-api>python ./tools/test-lib && ./tools/test-bots
############################################ Running tests for Bot library #############################################
test_resolve_bot_path (test_finder.FinderTestCase) ... ok
test_basics (test_lib.LibTest) ... ok
test_content_and_full_content (test_lib.LibTest) ... ok
test_extract_query_without_mention (test_lib.LibTest) ... ok
test_is_private_message_but_not_group_pm (test_lib.LibTest) ... ok
test_react (test_lib.LibTest) ... ok
test_run_message_handler_for_bot (test_lib.LibTest) ... ok
test_send_reply (test_lib.LibTest) ... ok
test_state_handler (test_lib.LibTest) ... ok
test_state_handler_by_mock (test_lib.LibTest) ... ok
test_upload_file (test_lib.LibTest) ... ok
test_upload_file_from_path (test_lib.LibTest) ... ok
test_extract_query_without_mention (test_run.TestBotLib) ... ok
test_adding_bot_parent_dir_to_sys_path_when_bot_name_specified (test_run.TestDefaultArguments) ... ok
test_adding_bot_parent_dir_to_sys_path_when_bot_path_specified (test_run.TestDefaultArguments) ... FAIL
test_argument_parsing_with_bot_name (test_run.TestDefaultArguments) ... ok
test_argument_parsing_with_bot_path (test_run.TestDefaultArguments) ... ok
test_run_bot_by_module_name (test_run.TestDefaultArguments) ... ok

======================================================================
FAIL: test_adding_bot_parent_dir_to_sys_path_when_bot_path_specified (test_run.TestDefaultArguments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\unittest\mock.py", line 1325, in patched
    return func(*newargs, **newkeywargs)
  File "S:\Sandy\Documents\College\Practice\Git\python-zulip-api\zulip_bots\zulip_bots\tests\test_run.py", line 57, in test_adding_bot_parent_dir_to_sys_path_when_bot_path_specified
    self._test_adding_bot_parent_dir_to_sys_path(bot_qualifier=bot_path, bot_dir_path=expected_bot_dir_path)
  File "S:\Sandy\Documents\College\Practice\Git\python-zulip-api\zulip_bots\zulip_bots\tests\test_run.py", line 66, in _test_adding_bot_parent_dir_to_sys_path
    self.assertIn(bot_dir_path, sys.path)
AssertionError: '/path/to' not found in ['S:\\path\\to', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_bots\\zulip_bots\\bots\\helloworld', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip_bots\\zulip_bots\\tests', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\tools', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv\\Scripts\\python38.zip', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv\\DLLs', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv\\lib', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv\\lib\\site-packages', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_bots', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_botserver', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip-api-py3-venv\\src\\zulint']

----------------------------------------------------------------------
Ran 18 tests in 0.134s

FAILED (failures=1)
Upasanadhameliya commented 3 years ago

@ganpa3 Even while testing the botserver

(zulip-api-py3-venv) (zulipenv) S:\Sandy\Documents\College\Practice\Git\python-zulip-api>python ./tools/test-botserver
############################################# Running tests for Botserver ##############################################
test_argument_parsing_defaults (tests.test_server.BotServerTests) ... ok
test_load_lib_modules (tests.test_server.BotServerTests) ... ERROR
test_read_config_file (tests.test_server.BotServerTests) ... WARNING:root:Single bot mode is enabled
WARNING:root:Sections except the 'giphy' will be ignored
WARNING:root:Single bot mode is enabled
WARNING:root:First bot name in the config list was changed from 'helloworld' to 'redefined_bot'
WARNING:root:Sections except the 'helloworld' will be ignored
ok
test_read_config_from_env_vars (tests.test_server.BotServerTests) ... WARNING:root:First bot name in the config list was changed from 'hello_world' to 'redefined_bot'
ok
test_request_for_unkown_bot (tests.test_server.BotServerTests) ... ok
test_successful_request (tests.test_server.BotServerTests) ... ok
test_successful_request_from_two_bots (tests.test_server.BotServerTests) ... ok
test_wrong_bot_credentials (tests.test_server.BotServerTests) ... ok
test_wrong_bot_token (tests.test_server.BotServerTests) ... ok

======================================================================
ERROR: test_load_lib_modules (tests.test_server.BotServerTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "S:\Sandy\Documents\College\Practice\Git\python-zulip-api\zulip_botserver\tests\test_server.py", line 235, in test_load_lib_modules
    with self.assertRaisesRegexp(SystemExit,  # type: ignore
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\unittest\case.py", line 1410, in deprecated_func
    return original_func(*args, **kwargs)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\unittest\case.py", line 1356, in assertRaisesRegex
    context = _AssertRaisesContext(expected_exception, self, expected_regex)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\unittest\case.py", line 173, in __init__
    expected_regex = re.compile(expected_regex)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\re.py", line 252, in compile
    return _compile(pattern, flags)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\sre_parse.py", line 525, in _parse
    code = _escape(source, this, state)
  File "c:\users\upasana\anaconda3\envs\zulipenv\lib\sre_parse.py", line 426, in _escape
    raise source.error("bad escape %s" % escape, len(escape))
re.error: bad escape \C at position 30

----------------------------------------------------------------------
Ran 9 tests in 0.208s

FAILED (errors=1)
LoopThrough-i-j commented 3 years ago

@ganpa3 Its not completely fixed

   self._test_adding_bot_parent_dir_to_sys_path(bot_qualifier=bot_path, bot_dir_path=expected_bot_dir_path)
 File "S:\Sandy\Documents\College\Practice\Git\python-zulip-api\zulip_bots\zulip_bots\tests\test_run.py", line 66, in _test_adding_bot_parent_dir_to_sys_path
   self.assertIn(bot_dir_path, sys.path)
AssertionError: '/path/to' not found in ['S:\\path\\to', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_bots\\zulip_bots\\bots\\helloworld', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip_bots\\zulip_bots\\tests', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\tools', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv\\Scripts\\python38.zip', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv\\DLLs', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv\\lib', 'c:\\users\\upasana\\anaconda3\\envs\\zulipenv', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv', 'S:\\Sandy\\Documents\\College\\Practice\\Git\\python-zulip-api\\zulip-api-py3-venv\\lib\\site-packages', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_bots', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip_botserver', 's:\\sandy\\documents\\college\\practice\\git\\python-zulip-api\\zulip-api-py3-venv\\src\\zulint']

----------------------------------------------------------------------
Ran 18 tests in 0.134s

FAILED (failures=1)

I think we need to replace these paths with the os.path.join version instead of hardcoding them as Linux paths. I think this is what the error demands us to.

ganpa3 commented 3 years ago

@timabbott Ping for a review.

timabbott commented 3 years ago

Merged, thanks @ganpa3!

I think a good follow-up project would be to look at setting up a GitHub Actions-based windows test to verify this doesn't regress in the future.

ganpa3 commented 3 years ago

@timabbott Made a PR to setup ci for Windows #662