Skip to content

Fix tests failing on Windows. #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2021
Merged

Fix tests failing on Windows. #652

merged 2 commits into from
Mar 4, 2021

Conversation

ganpa3
Copy link
Collaborator

@ganpa3 ganpa3 commented Feb 17, 2021

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

Fixes #651

Copy link

@Pradhvan Pradhvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏾

@Upasanadhameliya
Copy link
Collaborator

@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
Copy link
Collaborator

@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
Copy link
Contributor

@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.

@zulipbot zulipbot added size: M and removed size: S labels Feb 24, 2021
ganpa3 added 2 commits March 2, 2021 14:15
mypy version 0.770 has a bug where it raises false "syntax error in type
comment" warnings on Python 3.9
python/mypy#8627
It has been fixed.

zulint had a bug where it raised UnicodeDecodeError while running on
Windows, which has been fixed.
zulip/zulint@14e3974
Tests were failing on Windows since paths are case-insensitive on it.
This uses pathlib library to compare paths on all platforms.

Fixes #651
@ganpa3
Copy link
Collaborator Author

ganpa3 commented Mar 2, 2021

@timabbott Ping for a review.

@timabbott timabbott merged commit 44b6fd3 into zulip:master Mar 4, 2021
@timabbott
Copy link
Member

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 ganpa3 deleted the fix_tests branch March 5, 2021 03:36
@ganpa3
Copy link
Collaborator Author

ganpa3 commented Mar 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make tests work on Windows
7 participants