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

Changing message parsing in BaseLinter so it respects python.linting.maxNumberOfProblems #2208

Merged
merged 15 commits into from
Aug 28, 2018

Conversation

saponas
Copy link

@saponas saponas commented Jul 20, 2018

Fixes #2198

  • Title summarizes what is changing
  • Includes a news entry file (remember to thank yourself!)
  • Unit tests & code coverage are not adversely affected (within reason)
  • Works on all actively maintained versions of Python (e.g. Python 2.7 & the latest Python 3 release)
  • Works on Windows 10, macOS, and Linux (e.g. considered file system case-sensitivity)
    Only tested Win10
  • Dependencies are pinned (e.g. "1.2.3", not "^1.2.3")
  • package-lock.json has been regenerated if dependencies have changed

@codecov

This comment has been minimized.

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

Any chance you feel up to writing a unit test to make sure we don't break this in the future? 😉

const messages: ILintMessage[] = [];
let messageCount: number = 0;
let i: number;
for (i = messageCount; i < outputLines.length && messageCount < this.pythonSettings.linting.maxNumberOfProblems; i += 1)
Copy link
Member

Choose a reason for hiding this comment

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

Could this be simplified?:

for (let line of outputLines) {
    try {
        const msg = this.parseLine(line, regEx);
        if (msg) {
            messages.push(msg);
            if (messages.length >= this.pythonSettings.linting.maxNumberOfProblems) {
                break;
            }
        }
    } catch ...
}
return messages;

@brettcannon
Copy link
Member

@saponas no pressure on our part, but we are planning to code freeze for the August release next week, so if you could address my comment before then we can squeeze this in, else it will slip to the September release.

@saponas
Copy link
Author

saponas commented Aug 20, 2018

Thanks @brettcannon. I addressed them in a branch, but haven't merged them into this PR yet because I'm having trouble getting all the unit tests to run. (i.e., I'm having trouble testing my unit test :-). Any tips on how to get all the unit tests running correctly other than following the https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md

@brettcannon
Copy link
Member

@saponas what specifically is the issue? Is it simply running your tests or writing them?

/cc @d3r3kk and @ericsnowcurrently who have been doing a bunch of testing writing lately.

@saponas
Copy link
Author

saponas commented Aug 21, 2018

Thanks! I feel kinda silly that I couldn't get this working. From VS Code I'm running "Launch Tests" and seeing a bunch of unit test run in the DEBUG CONSOLE. Then some unit test fail in the ProcessService suite. Then the last test that runs is SocketCallbackHandler. The system never gets down to the lint tests (which is where I added my unit tests). I was hoping there is something obvious I'm missing on how to run the unit tests.

@d3r3kk
Copy link

d3r3kk commented Aug 22, 2018

Hey @saponas, it can be a bit daunting to run our tests as there are so many of them. To weed them out a little, you can do the following:

For unit tests: Those tests that are in files named *.unit.test.ts, alter the launch.json file in the "Debug Unit Tests" section by setting the grep field:

    "args": [
        "timeout=60000",
        "grep=[The suite name of your unit test file]"
    ],

...this will only run the suite with the tests you care about during a test run (be sure to set the debugger to run the Debug Unit Tests launcher).

If you are running system tests (we call them system tests, others call them integration or otherwise) you can achieve the same thing by editing the src/test/index.ts file here:

https://github.com/Microsoft/vscode-python/blob/b328ba12331ed34a267e32e77e3e4b1eff235c13/src/test/index.ts#L21

...to something like this:

const grep = '[The suite name of your *test.ts file]'; // IS_CI_SERVER &&...

...and then use the Launch Tests debugger launcher as you are doing now. This will run only the suite you name in the grep.

And be sure to escape any grep-sensitive characters in your suite name!

@saponas
Copy link
Author

saponas commented Aug 23, 2018

Hi @d3r3kk - Thanks for the help! That got me so I can run the linting system tests (including my system test). But it looks like they are all failing with not being able to find Python...

Python Extension: Linter 'pylint' is not installed. Please install it or select another linter". Error: spawn python ENOENT

Any tips on the setup for dev environment so that when I do "Launch Tests" it finds the Python environment? I have a conda environment with Python 2.7 that is selectable in the VS Code instance that I'm launching the tests from.

Here is the change I made to index.ts to get them running:

const grep = 'Linting \- General Tests';

Thanks!

@d3r3kk
Copy link

d3r3kk commented Aug 23, 2018

Oh yes, I'd forgotten about the Python interpreter that runs during testing. It will try and run the system default, unless you explicitly set the CI_PYTHON_PATH environment variable. Indeed, if you want to test against different versions of Python you must use this.

In the launch.json file, you can add the following to the Launch Tests setting:

    "env":{
        "CI_PYTHON_PATH": "/path/to/interpreter/of/choice/python"
    }

@d3r3kk
Copy link

d3r3kk commented Aug 23, 2018

(BTW: I am going to use this interaction to hopefully improve our docs on contributing...)

@saponas
Copy link
Author

saponas commented Aug 23, 2018

Thanks!!! That's exactly the info I needed! @brettcannon @d3r3kk

Added a system test to the PR. I tested that the test fails without this PR and passes after this PR. I also verified all the existing linting tests still pass.

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

Two fairly minor changes. Otherwise LGTM!

@@ -23,6 +23,7 @@ const pep8ConfigPath = path.join(pythoFilesPath, 'pep8config');
const pydocstyleConfigPath27 = path.join(pythoFilesPath, 'pydocstyleconfig27');
const pylintConfigPath = path.join(pythoFilesPath, 'pylintconfig');
const fileToLint = path.join(pythoFilesPath, 'file.py');
const threeLinLintsPath = path.join(pythoFilesPath, 'threeLineLints.py');
Copy link
Member

Choose a reason for hiding this comment

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

Typo in the name: threeLineLintsPath.

@@ -0,0 +1,15 @@
"""pylint messages with three lines of output"""
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comments what the linter warnings are triggered by and an example of what the linter warning is? This is to prevent someone from accidentally changing the file and breaking the test's expectations. It will also help for us to know the tests is testing multi-line tests. 😉

@saponas
Copy link
Author

saponas commented Aug 27, 2018

@brettcannon Thanks! I addressed both your comments.

@brettcannon brettcannon merged commit ed42722 into microsoft:master Aug 28, 2018
@brettcannon
Copy link
Member

@saponas Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants