FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add env flag for running tests with pycodestyle by ryanashcraft · Pull Request #70 · prettier/plugin-python · GitHub

This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
62 changes: 62 additions & 0 deletions tests_config/pycodestyle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";

const spawnSync = require("child_process").spawnSync;
const path = require("path");
const normalizeOptions = require("prettier/src/main/options").normalize;

// Only enable subset of errors that prettier should handle and use the
// default ignored error list.
// See http://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
const selectedErrors = ["E1", "E2", "E3", "W1", "W2", "W3", "W5"];
const ignoredErrors = [
"E121",
"E123",
"E126",
"E133",
"E226",
"E241",
"E242",
"E704",
"W503",
"W504"
];

function getPycodestyleOutput(string, options) {
const normalizedOptions = normalizeOptions(options);

// Use the same version of Python to run pycodestyle that we're using for
// prettier.
const pythonExectuable = `python${
normalizedOptions.pythonVersion == "2" ? "" : "3"
}`;

const executionResult = spawnSync(
pythonExectuable,
[
path.join(__dirname, "../vendor/python/pycodestyle.py"),
`--select=${selectedErrors.join(",")}`,
`--ignore=${ignoredErrors.join(",")}`,
`--max-line-length=${normalizedOptions.printWidth}`,
"-"
],
{
input: string
}
);

if (!executionResult.stderr) {
throw new Error("Failed to execute pycodestyle");
}

const error = executionResult.stderr.toString();

if (error) {
throw new Error(error);
}

return executionResult.stdout.toString();
}

module.exports = {
getPycodestyleOutput: getPycodestyleOutput
};
6 changes: 6 additions & 0 deletions tests_config/run_spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const extname = require("path").extname;
const prettier = require("prettier");
const massageAST = require("prettier/src/common/clean-ast").massageAST;
const normalizeOptions = require("prettier/src/main/options").normalize;
const getPycodestyleOutput = require("./pycodestyle").getPycodestyleOutput;

const AST_COMPARE = process.env["AST_COMPARE"];
const PEP8_VALIDATE = process.env["PEP8_VALIDATE"];

function run_spec(dirname, parsers, options) {
options = Object.assign(
Expand Down Expand Up @@ -39,6 +41,10 @@ function run_spec(dirname, parsers, options) {
expect(raw(source + "~".repeat(80) + "\n" + output)).toMatchSnapshot(
filename
);

if (PEP8_VALIDATE) {
expect(getPycodestyleOutput(output, mergedOptions)).toEqual("");
}
});

parsers.slice(1).forEach(parserName => {
Expand Down
Loading

Back | FazBrowse Home | New Git URL