Skip to content
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

Test failure in test_file_path_completions #1395

Closed
Apteryks opened this issue Sep 10, 2019 · 8 comments
Closed

Test failure in test_file_path_completions #1395

Apteryks opened this issue Sep 10, 2019 · 8 comments

Comments

@Apteryks
Copy link
Contributor

While working on packaging 0.15.1 for GNU Guix, I encountered the following repeatable test failure:

 =================================== FAILURES ===================================
____ test_file_path_completions[example.py-rb"../jedi/tes-None-expected12] _____

Script = functools.partial(<class 'jedi.api.Script'>, environment=<Environment: 3.7.0 in /gnu/store/b7fqhszxl02g6pfm3vw6b3cjz472qrly-python-3.7.0>)
file = 'example.py', code = 'rb"../jedi/tes', column = None, expected = ['t/']

    @pytest.mark.parametrize(
        'file, code, column, expected', [
            # General tests / relative paths
            (None, '"comp', None, ['ile', 'lex']),  # No files like comp
            (None, '"test', None, [s]),
            (None, '"test', 4, ['t' + s]),
            ('example.py', '"test%scomp' % s, None, ['letion' + s]),
            ('example.py', 'r"comp"', None, "A LOT"),
            ('example.py', 'r"tes"', None, "A LOT"),
            ('example.py', 'r"tes"', 5, ['t' + s]),
            ('example.py', 'r" tes"', 6, []),
            ('test%sexample.py' % se, 'r"tes"', 5, ['t' + s]),
            ('test%sexample.py' % se, 'r"test%scomp"' % s, 5, ['t' + s]),
            ('test%sexample.py' % se, 'r"test%scomp"' % s, 11, ['letion' + s]),
            ('test%sexample.py' % se, '"%s"' % join('test', 'completion', 'basi'), 21, ['c.py']),
            ('example.py', 'rb"' + join('..', 'jedi', 'tes'), None, ['t' + s]),
    
            # Absolute paths
            (None, '"' + join(root_dir, 'test', 'test_ca'), None, ['che.py"']),
            (None, '"%s"' % join(root_dir, 'test', 'test_ca'), len(root_dir) + 14, ['che.py']),
    
            # Longer quotes
            ('example.py', 'r"""test', None, [s]),
            ('example.py', 'r"""\ntest', None, []),
            ('example.py', 'u"""tes\n', (1, 7), ['t' + s]),
            ('example.py', '"""test%stest_cache.p"""' % s, 20, ['y']),
            ('example.py', '"""test%stest_cache.p"""' % s, 19, ['py"""']),
    
            # Adding
            ('example.py', '"test" + "%stest_cac' % se, None, ['he.py"']),
            ('example.py', '"test" + "%s" + "test_cac' % se, None, ['he.py"']),
            ('example.py', 'x = 1 + "test', None, []),
            ('example.py', 'x = f("te" + "st)', 16, [s]),
            ('example.py', 'x = f("te" + "st', 16, [s]),
            ('example.py', 'x = f("te" + "st"', 16, [s]),
            ('example.py', 'x = f("te" + "st")', 16, [s]),
            ('example.py', 'x = f("t" + "est")', 16, [s]),
            # This is actually not correct, but for now leave it here, because of
            # Python 2.
            ('example.py', 'x = f(b"t" + "est")', 17, [s]),
            ('example.py', '"test" + "', None, [s]),
    
            # __file__
            (f1, os_path + 'dirname(__file__) + "%stest' % s, None, [s]),
            (f2, os_path + 'dirname(__file__) + "%stest_ca' % se, None, ['che.py"']),
            (f2, os_path + 'dirname(abspath(__file__)) + sep + "test_ca', None, ['che.py"']),
            (f2, os_path + 'join(dirname(__file__), "completion") + sep + "basi', None, ['c.py"']),
            (f2, os_path + 'join("test", "completion") + sep + "basi', None, ['c.py"']),
    
            # inside join
            (f2, os_path + 'join(dirname(__file__), "completion", "basi', None, ['c.py"']),
            (f2, os_path + 'join(dirname(__file__), "completion", "basi)', 43, ['c.py"']),
            (f2, os_path + 'join(dirname(__file__), "completion", "basi")', 43, ['c.py']),
            (f2, os_path + 'join(dirname(__file__), "completion", "basi)', 35, ['']),
            (f2, os_path + 'join(dirname(__file__), "completion", "basi)', 33, ['on"']),
            (f2, os_path + 'join(dirname(__file__), "completion", "basi")', 33, ['on"']),
    
            # join with one argument. join will not get evaluated and the result is
            # that directories and in a slash. This is unfortunate, but doesn't
            # really matter.
            (f2, os_path + 'join("tes', 9, ['t"']),
            (f2, os_path + 'join(\'tes)', 9, ["t'"]),
            (f2, os_path + 'join(r"tes"', 10, ['t']),
            (f2, os_path + 'join("""tes""")', 11, ['t']),
    
            # Almost like join but not really
            (f2, os_path + 'join["tes', 9, ['t' + s]),
            (f2, os_path + 'join["tes"', 9, ['t' + s]),
            (f2, os_path + 'join["tes"]', 9, ['t' + s]),
            (f2, os_path + 'join[dirname(__file__), "completi', 33, []),
            (f2, os_path + 'join[dirname(__file__), "completi"', 33, []),
            (f2, os_path + 'join[dirname(__file__), "completi"]', 33, []),
    
            # With full paths
            (f2, 'import os\nos.path.join(os.path.dirname(__file__), "completi', 49, ['on"']),
            (f2, 'import os\nos.path.join(os.path.dirname(__file__), "completi"', 49, ['on']),
            (f2, 'import os\nos.path.join(os.path.dirname(__file__), "completi")', 49, ['on']),
    
            # With alias
            (f2, 'import os.path as p as p\np.join(p.dirname(__file__), "completi', None, ['on"']),
            (f2, 'from os.path import dirname, join as j\nj(dirname(__file__), "completi',
             None, ['on"']),
    
            # Trying to break it
            (f2, os_path + 'join(["tes', 10, ['t' + s]),
            (f2, os_path + 'join(["tes"]', 10, ['t' + s]),
            (f2, os_path + 'join(["tes"])', 10, ['t' + s]),
            (f2, os_path + 'join("test", "test_cac" + x,', 22, ['he.py']),
        ]
    )
    def test_file_path_completions(Script, file, code, column, expected):
        line = None
        if isinstance(column, tuple):
            line, column = column
        comps = Script(code, path=file, line=line, column=column).completions()
        if expected == "A LOT":
            assert len(comps) > 100  # This is basically global completions.
        else:
>           assert [c.complete for c in comps] == expected
E           AssertionError: assert [] == ['t/']
E             Right contains more items, first extra item: 't/'
E             Use -v to get the full diff

test/test_api/test_completion.py:267: AssertionError
======== 1 failed, 2527 passed, 56 skipped, 5 xfailed in 129.23 seconds ========
@davidhalter
Copy link
Owner

Can you send me the way how you run tests? In which directory are you? I would need pretty much the exact reproduction steps, because the CI passes.

@Apteryks
Copy link
Contributor Author

Can you send me the way how you run tests? In which directory are you? I would need pretty much the exact reproduction steps, because the CI passes.

It's nothing very special, I'm afraid; from the root of the project (where the file setup.py lives), I run the following command:

python -m pytest

And the failure shown above is triggered.

@Apteryks

This comment has been minimized.

@Apteryks

This comment has been minimized.

@Apteryks
Copy link
Contributor Author

Apteryks commented Sep 13, 2019

@davidhalter Nevermind my two previous posts.... It does seem to work, using:

FROM debian:testing

RUN apt-get update && apt-get install -y \
    git \
    python3 \
    python3-pip \
    python3-pytest \
    python3-docopt

RUN mkdir -p /root/src/ \
    && git clone --recursive https://github.com/davidhalter/jedi.git /root/src/jedi \
    && cd /root/src/jedi \
    && git checkout v0.15.1 \
    && git submodule update

# RUN pip3 install git+https://github.com/davidhalter/parso.git@v0.5.1
RUN pip3 install parso==0.5.1

CMD cd /root/src/jedi && python3 -m pytest

Will dig further to try to isolate what is causing the problem in the Guix environment... it's weird.

@Apteryks
Copy link
Contributor Author

Haha! I took some time to read what the test is doing... and to reproduce, it suffices to rename the checkout directory to something else than 'jedi', e.g.: jedi-src or whatever:

FROM debian:testing

RUN apt-get update && apt-get install -y \
    git \
    python3 \
    python3-pip \
    python3-pytest \
    python3-docopt

RUN mkdir -p /root/src/ \
    && git clone --recursive https://github.com/davidhalter/jedi.git /root/jedi-src \
    && cd /root/jedi-src \
    && git checkout v0.15.1 \
    && git submodule update

# RUN pip3 install git+https://github.com/davidhalter/parso.git@v0.5.1
RUN pip3 install parso==0.5.1

CMD cd /root/jedi-src && python3 -m pytest

Apteryks added a commit to Apteryks/jedi that referenced this issue Sep 13, 2019
This fixes issue davidhalter#1395 (see:
davidhalter#1395).

* test/test_api/test_completion.py(current_dirname): New variable.
(test_file_path_completions): Use it.
davidhalter pushed a commit that referenced this issue Sep 19, 2019
This fixes issue #1395 (see:
#1395).

* test/test_api/test_completion.py(current_dirname): New variable.
(test_file_path_completions): Use it.
@davidhalter
Copy link
Owner

Thanks for fixing this!

BTW: If you write fixes #1395 instead of This fixes issue #1395, Github will automatically close this issue.

@Apteryks
Copy link
Contributor Author

Good to know! Thanks for reviewing and merging this :-)

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

No branches or pull requests

2 participants