2014-01-16 22:07:18 +04:00
|
|
|
"""test line matching with some failing examples and some which warn
|
|
|
|
|
|
|
|
run-test.t only checks positive matches and can not see warnings
|
|
|
|
(both by design)
|
|
|
|
"""
|
2016-04-13 22:33:24 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2014-01-16 22:07:18 +04:00
|
|
|
|
2016-04-13 22:33:24 +03:00
|
|
|
import doctest
|
|
|
|
import os
|
|
|
|
import re
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
|
|
|
|
2014-01-17 15:46:29 +04:00
|
|
|
# this is hack to make sure no escape characters are inserted into the output
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if "TERM" in os.environ:
|
|
|
|
del os.environ["TERM"]
|
|
|
|
run_tests = __import__("run-tests")
|
|
|
|
|
2014-01-16 22:07:18 +04:00
|
|
|
|
2015-04-14 17:57:15 +03:00
|
|
|
def prn(ex):
|
|
|
|
m = ex.args[0]
|
|
|
|
if isinstance(m, str):
|
|
|
|
print(m)
|
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
print(m.decode("utf-8"))
|
|
|
|
|
2015-04-14 17:57:15 +03:00
|
|
|
|
2014-01-16 22:07:18 +04:00
|
|
|
def lm(expected, output):
|
|
|
|
r"""check if output matches expected
|
|
|
|
|
|
|
|
does it generally work?
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'H*e (glob)\n', b'Here\n')
|
2014-01-16 22:07:18 +04:00
|
|
|
True
|
|
|
|
|
|
|
|
fail on bad test data
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> try: lm(b'a\n',b'a')
|
|
|
|
... except AssertionError as ex: print(ex)
|
2014-01-16 22:07:18 +04:00
|
|
|
missing newline
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> try: lm(b'single backslash\n', b'single \backslash\n')
|
|
|
|
... except AssertionError as ex: prn(ex)
|
2014-01-16 22:07:18 +04:00
|
|
|
single backslash or unknown char
|
|
|
|
"""
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
assert expected.endswith(b"\n") and output.endswith(b"\n"), "missing newline"
|
|
|
|
assert not re.search(
|
|
|
|
br"[^ \w\\/\r\n()*?]", expected + output
|
|
|
|
), b"single backslash or unknown char"
|
|
|
|
test = run_tests.TTest(b"test-run-test.t", b".", b".")
|
2017-07-18 07:12:44 +03:00
|
|
|
match = test.linematch(expected, output)
|
2014-01-16 15:08:29 +04:00
|
|
|
if isinstance(match, str):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return "special: " + match
|
2015-04-14 17:57:15 +03:00
|
|
|
elif isinstance(match, bytes):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return "special: " + match.decode("utf-8")
|
2014-01-16 15:08:29 +04:00
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return bool(match) # do not return match object
|
|
|
|
|
2014-01-16 22:07:18 +04:00
|
|
|
|
|
|
|
def wintests():
|
|
|
|
r"""test matching like running on windows
|
|
|
|
|
|
|
|
enable windows matching on any os
|
|
|
|
>>> _osaltsep = os.altsep
|
|
|
|
>>> os.altsep = True
|
2017-12-10 08:00:36 +03:00
|
|
|
>>> _osname = os.name
|
|
|
|
>>> os.name = 'nt'
|
2014-01-16 22:07:18 +04:00
|
|
|
|
|
|
|
valid match on windows
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n')
|
2014-01-16 22:07:18 +04:00
|
|
|
True
|
|
|
|
|
|
|
|
direct matching, glob unnecessary
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'g/b (glob)\n', b'g/b\n')
|
2014-01-16 15:08:57 +04:00
|
|
|
'special: -glob'
|
2014-01-16 22:07:18 +04:00
|
|
|
|
|
|
|
missing glob
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'/g/c/d/fg\n', b'\\g\\c\\d/fg\n')
|
run-tests: accept '\' vs '/' path differences without '(glob)'
Having to constantly adjust these is a hassle. It's easy for this to slip by
when not testing on Windows, and then when it happens on stable, the tests fail
for the next 3 months if we follow the rules for stable.
This works the same way the EOL differences are ignored, namely to adjust on the
fly and recheck on Windows. I can't think of any situation where there would be
a '\' on Windows, a '/' elsewhere, and the '/' should be considered a failure on
Windows.
This fixes the obvious output problems where (glob) is missing. Without this,
test-alias.t, test-remotenames.t and test-largefiles-misc.t are failing. The
flip side (not handled by this) is the case where an unnecessary glob is
present. There seems to be two separate behaviors. f3517e22bfa1 is an example
of where the test has been autocorrecting (with output differences), and
ed159a9fcf2a is an example where the test fails and reports 'no result code from
test'. Hopefully those cases will become even more rare if people don't need to
guess at when a glob is needed for a Windows path.
It's probably unreasonable to submit a single patch that wipes out all of the
(glob) instances that were only used to hide path differences, given the churn
from other contributors. Since their presence isn't harming the tests, these
can be removed through attrition.
2017-12-10 08:16:11 +03:00
|
|
|
True
|
2017-12-10 08:00:36 +03:00
|
|
|
>>> lm(b'/g/c/d/fg\n', b'\\g\\c\\d\\fg\r\n')
|
run-tests: accept '\' vs '/' path differences without '(glob)'
Having to constantly adjust these is a hassle. It's easy for this to slip by
when not testing on Windows, and then when it happens on stable, the tests fail
for the next 3 months if we follow the rules for stable.
This works the same way the EOL differences are ignored, namely to adjust on the
fly and recheck on Windows. I can't think of any situation where there would be
a '\' on Windows, a '/' elsewhere, and the '/' should be considered a failure on
Windows.
This fixes the obvious output problems where (glob) is missing. Without this,
test-alias.t, test-remotenames.t and test-largefiles-misc.t are failing. The
flip side (not handled by this) is the case where an unnecessary glob is
present. There seems to be two separate behaviors. f3517e22bfa1 is an example
of where the test has been autocorrecting (with output differences), and
ed159a9fcf2a is an example where the test fails and reports 'no result code from
test'. Hopefully those cases will become even more rare if people don't need to
guess at when a glob is needed for a Windows path.
It's probably unreasonable to submit a single patch that wipes out all of the
(glob) instances that were only used to hide path differences, given the churn
from other contributors. Since their presence isn't harming the tests, these
can be removed through attrition.
2017-12-10 08:16:11 +03:00
|
|
|
True
|
2014-01-16 22:07:18 +04:00
|
|
|
|
|
|
|
restore os.altsep
|
|
|
|
>>> os.altsep = _osaltsep
|
2017-12-10 08:00:36 +03:00
|
|
|
>>> os.name = _osname
|
2014-01-16 22:07:18 +04:00
|
|
|
"""
|
2014-01-17 15:46:29 +04:00
|
|
|
pass
|
2014-01-16 22:07:18 +04:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2014-01-16 22:07:18 +04:00
|
|
|
def otherostests():
|
|
|
|
r"""test matching like running on non-windows os
|
|
|
|
|
|
|
|
disable windows matching on any os
|
|
|
|
>>> _osaltsep = os.altsep
|
|
|
|
>>> os.altsep = False
|
2017-12-10 08:00:36 +03:00
|
|
|
>>> _osname = os.name
|
|
|
|
>>> os.name = 'nt'
|
2014-01-16 22:07:18 +04:00
|
|
|
|
|
|
|
backslash does not match slash
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'h/a* (glob)\n', b'h\\ab\n')
|
2014-01-16 22:07:18 +04:00
|
|
|
False
|
|
|
|
|
|
|
|
direct matching glob can not be recognized
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'h/b (glob)\n', b'h/b\n')
|
2014-01-16 22:07:18 +04:00
|
|
|
True
|
|
|
|
|
|
|
|
missing glob can not not be recognized
|
2015-04-14 17:57:15 +03:00
|
|
|
>>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n')
|
2014-01-16 22:07:18 +04:00
|
|
|
False
|
|
|
|
|
|
|
|
restore os.altsep
|
|
|
|
>>> os.altsep = _osaltsep
|
2017-12-10 08:00:36 +03:00
|
|
|
>>> os.name = _osname
|
2014-01-16 22:07:18 +04:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2014-01-16 22:07:18 +04:00
|
|
|
doctest.testmod()
|