diff --git a/.appveyor.yml b/.appveyor.yml index f53ab5b41..6ab62acda 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,9 +1,6 @@ version: 0.4.3.{build} os: Windows Server 2012 R2 install: -- C:\Python35\Scripts\pip install ply pyreadline pytest pygments prompt_toolkit -build_script: -- C:\Python35\python setup.py install +- C:\Python35\Scripts\pip install --upgrade -r requirements-tests.txt test_script: - C:\Python35\Scripts\py.test - diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..aa4806b0d --- /dev/null +++ b/.coveragerc @@ -0,0 +1,7 @@ +[run] +branch = true +omit = + tests/* + xonsh/__amalgam__.py + */parser*_table.py + setup.py diff --git a/.travis.yml b/.travis.yml index a676d4473..7f1fcf7d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ python: - 3.5 - "nightly" install: - - pip install -r requirements-tests.txt + - pip install --upgrade -r requirements-tests.txt script: - - coverage run --source xonsh -m py.test -q + - py.test --flake8 --cov=. --cov-report=term after_success: - codecov diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..0b7a75eae --- /dev/null +++ b/conftest.py @@ -0,0 +1,2 @@ +# empty file to trick py.test into adding the root folder to sys.path +# see https://github.com/pytest-dev/pytest/issues/911 for more info diff --git a/requirements-tests.txt b/requirements-tests.txt index db2a85c2b..fc513fe37 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,6 +1,7 @@ ply pytest +pytest-flake8 +pytest-cov prompt-toolkit pygments -coverage codecov diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..752b61a3c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[pytest] +addopts = --flake8 +flake8-max-line-length = 180 +flake8-ignore = + # Temporary until we fix all the errors + *.py E301 E302 E303 W391 E402 E127 E128 E201 E731 E701 E271 E265 E266 E225 E202 E502 E231 E228 E227 E203 E122 E251 W291 E124 E261 E125 E111 E222 E272 F401 F811 F841 F821 F402 + __amalgam__.py ALL + # test files should be PEP8 but a ton of errors for now + test_*.py ALL + # we don't care about sphinx autogenerated files + docs/*.py ALL + # we don't care about ply files? + ply/*.py ALL + # these run VERY slowly and give tons of errors + parser*_table.py ALL diff --git a/tests/test_tools.py b/tests/test_tools.py index e9fe6a6c0..22538a44a 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -978,46 +978,42 @@ def test_argvquote(st, esc): assert esc == obs -_leaders = ('', 'not empty') -_r = ('r', '') -_b = ('b', '') -_u = ('u', '') -_chars = set(i+j+k for i in _r for j in _b for k in _u) -_chars |= set(i+j+k for i in _r for j in _u for k in _b) -_chars |= set(i+j+k for i in _b for j in _u for k in _r) -_chars |= set(i+j+k for i in _b for j in _r for k in _u) -_chars |= set(i+j+k for i in _u for j in _r for k in _b) -_chars |= set(i+j+k for i in _u for j in _b for k in _r) -_squote = ('"""', '"', "'''", "'") -_startend = {c+s: s for c in _chars for s in _squote} - -inners = "this is a string" +@pytest.mark.parametrize('inp', ['no string here', '']) +def test_partial_string_none(inp): + assert check_for_partial_string(inp) == (None, None, None) -def test_partial_string(): - # single string at start - assert check_for_partial_string('no strings here') == (None, None, None) - assert check_for_partial_string('') == (None, None, None) - for s, e in _startend.items(): - _test = s + inners + e - for l in _leaders: - for f in _leaders: - # single string - _res = check_for_partial_string(l + _test + f) - assert _res == (len(l), len(l) + len(_test), s) - # single partial - _res = check_for_partial_string(l + f + s + inners) - assert _res == (len(l+f), None, s) - for s2, e2 in _startend.items(): - _test2 = s2 + inners + e2 - for l2 in _leaders: - for f2 in _leaders: - # two strings - _res = check_for_partial_string(l + _test + f + l2 + _test2 + f2) - assert _res == (len(l+_test+f+l2), len(l+_test+f+l2+_test2), s2) - # one string, one partial - _res = check_for_partial_string(l + _test + f + l2 + s2 + inners) - assert _res == (len(l+_test+f+l2), None, s2) +@pytest.mark.parametrize('leaders', [ + (('', 0), ('not empty', 9)), + (('not empty', 9), ('', 0)) +]) +@pytest.mark.parametrize('prefix', ['b', 'rb', 'r' ]) +@pytest.mark.parametrize('quote', ['"', '"""']) +def test_partial_string(leaders, prefix, quote): + (l, l_len), (f, f_len) = leaders + s = prefix + quote + t = s + 'test string' + quote + t_len = len(t) + # single string + test_string = l + t + f + obs = check_for_partial_string(test_string) + exp = l_len, l_len + t_len, s + assert obs == exp + # single partial + test_string = l + f + s + 'test string' + obs = check_for_partial_string(test_string) + exp = l_len + f_len, None, s + assert obs == exp + # two strings + test_string = l + t + f + l + t + f + obs = check_for_partial_string(test_string) + exp = (l_len + t_len + f_len + l_len), (l_len + t_len + f_len + l_len + t_len), s + assert obs == exp + # one string, one partial + test_string = l + t + f + l + s + 'test string' + obs = check_for_partial_string(test_string) + exp = l_len + t_len + f_len + l_len , None, s + assert obs == exp def test_executables_in(xonsh_builtins): diff --git a/xonsh/environ.py b/xonsh/environ.py index 80caebb73..5c4c69402 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -984,7 +984,7 @@ def current_branch(pad=NotImplemented): if isinstance(branch, subprocess.TimeoutExpired): branch = '' _first_branch_timeout_message() - return branch + return branch or None def git_dirty_working_directory(cwd=None, include_untracked=False):