├── .eslintrc.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── jest.eslint.config.js ├── jest.test.config.js ├── package.json ├── src ├── _util-from-prettier.js ├── index.js ├── parser.js └── printer │ ├── index.js │ └── tokens.js ├── tests ├── python3_args_mixed │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── args_mixed.py │ └── jsfmt.spec.js ├── python3_async_func │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── async_func.py │ └── jsfmt.spec.js ├── python3_aug_assign │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── aug_assign.py │ └── jsfmt.spec.js ├── python3_await │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── await.py │ └── jsfmt.spec.js ├── python3_f_strings │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── f_strings.py │ └── jsfmt.spec.js ├── python3_kwargs_only │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── kwargs_only.py ├── python3_nonlocal │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── nonlocal.py ├── python_ann_assign │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── ann_assign.py │ └── jsfmt.spec.js ├── python_arg_annotations │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── args_annotations.py │ └── jsfmt.spec.js ├── python_args │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── args.py │ └── jsfmt.spec.js ├── python_args_mixed │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── args_mixed.py │ └── jsfmt.spec.js ├── python_assert │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── assert.py │ └── jsfmt.spec.js ├── python_assign │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── assign.py │ └── jsfmt.spec.js ├── python_attributes │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── attributes.py │ └── jsfmt.spec.js ├── python_aug_assign │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── aug_assign.py │ └── jsfmt.spec.js ├── python_bin_op │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── bin_op.py │ └── jsfmt.spec.js ├── python_blank_lines_indented │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── blank_lines_indented.py │ └── jsfmt.spec.js ├── python_blank_lines_top_level │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── blank_lines_top_level.py │ └── jsfmt.spec.js ├── python_bool_op │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── bool_op.py │ └── jsfmt.spec.js ├── python_bytes │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── bytes.py │ └── jsfmt.spec.js ├── python_call │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── call.py │ └── jsfmt.spec.js ├── python_call_mixed │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── call_mixed.py │ └── jsfmt.spec.js ├── python_class │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── class.py │ └── jsfmt.spec.js ├── python_comments │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── comments.py │ └── jsfmt.spec.js ├── python_compare │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── compare.py │ └── jsfmt.spec.js ├── python_dangling_comments │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── dangling_comments.py │ └── jsfmt.spec.js ├── python_decorators │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── decorators.py │ └── jsfmt.spec.js ├── python_default_args │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── default_args.py │ └── jsfmt.spec.js ├── python_delete │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── delete.py │ └── jsfmt.spec.js ├── python_dict │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── dict.py │ └── jsfmt.spec.js ├── python_dict_comp │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── dict_comp.py │ └── jsfmt.spec.js ├── python_elif_multi_body │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── elif_multi_body.py │ └── jsfmt.spec.js ├── python_empty │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── empty_file.py │ ├── jsfmt.spec.js │ └── single_space.py ├── python_expressions │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── expressions.py │ └── jsfmt.spec.js ├── python_float │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── float.py │ └── jsfmt.spec.js ├── python_for │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── for.py │ └── jsfmt.spec.js ├── python_for_else │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── for_else.py │ └── jsfmt.spec.js ├── python_for_kv │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── for_kw.py │ └── jsfmt.spec.js ├── python_generator_expressions │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── generator_expressions.py │ └── jsfmt.spec.js ├── python_global │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── global.py │ └── jsfmt.spec.js ├── python_hello │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── hello.py │ └── jsfmt.spec.js ├── python_if │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── if.py │ └── jsfmt.spec.js ├── python_import │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── import.py │ └── jsfmt.spec.js ├── python_inline_comments │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── inline_comments.py │ └── jsfmt.spec.js ├── python_kwargs │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── kwargs.py ├── python_lambdas │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── lambdas.py ├── python_list │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── list.py ├── python_list_comp │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── list_comp.py ├── python_long │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── hello.py │ └── jsfmt.spec.js ├── python_nested_if │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── nested_if.py ├── python_not_in │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── not_in.py ├── python_pass │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── pass.py ├── python_print_width │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── print_width.py ├── python_raise │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── raise.py ├── python_return │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── return.py ├── python_set │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── set.py ├── python_set_comp │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── set_comp.py ├── python_slices │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── list.py ├── python_starred │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── starred.py ├── python_str_token │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── str_token.py ├── python_strings │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── strings.py ├── python_subscript │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── subscript.py ├── python_tagged_strings │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── tagged_strings.py ├── python_try │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── try.py ├── python_tuple │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── tuple.py ├── python_uadd │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── uadd.py ├── python_while │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── while.py ├── python_with │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── with.py ├── python_yield │ ├── __snapshots__ │ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── yield.py └── python_yield_from │ ├── __snapshots__ │ └── jsfmt.spec.js.snap │ ├── jsfmt.spec.js │ └── yield_from.py ├── tests_config ├── pycodestyle.js ├── raw-serializer.js └── run_spec.js ├── vendor └── python │ ├── astexport.py │ ├── asttokens │ ├── __init__.py │ ├── asttokens.py │ ├── line_numbers.py │ ├── mark_tokens.py │ └── util.py │ ├── pycodestyle.py │ └── six.py └── yarn.lock /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: 3 | - eslint:recommended 4 | - plugin:prettier/recommended 5 | - plugin:jest/recommended 6 | plugins: 7 | - import 8 | root: true 9 | env: 10 | es6: true 11 | node: true 12 | jest: true 13 | rules: 14 | curly: error 15 | import/no-extraneous-dependencies: 16 | - error 17 | - devDependencies: ["tests*/**", "scripts/**"] 18 | no-else-return: error 19 | no-inner-declarations: error 20 | no-unneeded-ternary: error 21 | no-useless-return: error 22 | no-var: error 23 | one-var: 24 | - error 25 | - never 26 | prefer-arrow-callback: error 27 | prefer-const: error 28 | react/no-deprecated: off 29 | strict: error 30 | symbol-description: error 31 | yoda: 32 | - error 33 | - never 34 | - exceptRange: true 35 | overrides: 36 | - files: "tests/**/*.js" 37 | rules: 38 | strict: off 39 | globals: 40 | run_spec: true 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | /test.py 4 | /.vscode 5 | .DS_Store 6 | coverage 7 | .idea 8 | __pycache__/ 9 | *.pyc 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - 6 5 | - 8 6 | - 9 7 | cache: 8 | yarn: true 9 | directories: 10 | - node_modules 11 | - /home/travis/.pyenv_cache 12 | install: 13 | - yarn install 14 | before_install: 15 | - export PYTHON_BUILD_CACHE_PATH="/home/travis/.pyenv_cache" 16 | - curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash 17 | - export PATH="/home/travis/.pyenv/bin:$PATH" 18 | - eval "$(pyenv init -)" 19 | - eval "$(pyenv virtualenv-init -)" 20 | - pyenv install -s 2.7.11 21 | - pyenv install -s 3.6.3 22 | - pyenv global 2.7.11 3.6.3 23 | script: 24 | - AST_COMPARE=1 yarn test -- --runInBand 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017-2019 Patrick Guido Arminio 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This plugin is deprecated. 2 | 3 | We recommend you use [Black](https://github.com/ambv/black) instead. 4 | 5 | --- 6 | 7 |
8 | Prettier 10 | Python 14 |
15 | 16 |

Prettier Python Plugin

17 | 18 |

19 | 20 | Gitter 21 | 22 | 23 | Travis 24 | 25 | 26 | npm version 27 | 28 | 31 | 32 | code style: prettier 33 | 34 | 35 | Follow+Prettier+on+Twitter 36 | 37 |

38 | 39 | ## WORK IN PROGRESS 40 | 41 | Please note that this plugin is under active development, and might not be ready to run on production code yet. 42 | 43 | ## Contributing 44 | 45 | If you're interested in contributing to the development of Prettier for Python, you can follow the [CONTRIBUTING guide from Prettier](https://github.com/prettier/prettier/blob/master/CONTRIBUTING.md), as it all applies to this repository too. 46 | 47 | To test it out on a Python file: 48 | 49 | * Clone this repository. 50 | * Run `yarn`. 51 | * Create a file called `test.py`. 52 | * Run `yarn prettier test.py` to check the output. 53 | * Run `yarn prettier -- --write test.py` to rewrite file. 54 | * Check out `yarn prettier -- --help` for other options. 55 | 56 | ## Install 57 | 58 | ```bash 59 | yarn add --dev --exact prettier @prettier/plugin-python 60 | ``` 61 | 62 | ## Use 63 | 64 | ```bash 65 | prettier --write "**/*.py" 66 | ``` 67 | 68 | ## Maintainers 69 | 70 | 71 | 72 | 73 | 80 | 87 | 94 | 95 | 96 |
74 | 75 | 76 |
77 | Patrick Arminio 78 |
79 |
81 | 82 | 83 |
84 | Danny Weinberg 85 |
86 |
88 | 89 | 90 |
91 | Ryan Ashcraft 92 |
93 |
97 | -------------------------------------------------------------------------------- /jest.eslint.config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | runner: "jest-runner-eslint", 5 | displayName: "lint", 6 | testMatch: ["/**/*.js"], 7 | testPathIgnorePatterns: ["node_modules/"] 8 | }; 9 | -------------------------------------------------------------------------------- /jest.test.config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const ENABLE_COVERAGE = false; // !!process.env.CI; 4 | 5 | module.exports = { 6 | displayName: "test", 7 | setupFiles: ["/tests_config/run_spec.js"], 8 | snapshotSerializers: ["/tests_config/raw-serializer.js"], 9 | testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", 10 | testPathIgnorePatterns: ["tests/new_react", "tests/more_react"], 11 | collectCoverage: ENABLE_COVERAGE, 12 | collectCoverageFrom: ["src/**/*.js", "!/node_modules/"], 13 | transform: {} 14 | }; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@prettier/plugin-python", 3 | "version": "0.0.0-development", 4 | "description": "Prettier Python Plugin", 5 | "main": "src", 6 | "repository": "https://github.com/prettier/prettier-python", 7 | "author": "Lucas Azzola <@azz>", 8 | "license": "MIT", 9 | "files": [ 10 | "src", 11 | "vendor" 12 | ], 13 | "engines": { 14 | "node": ">=6" 15 | }, 16 | "dependencies": { 17 | "prettier": "prettier/prettier#d05a29da05b2084790491eaef85917ce584e4fbd" 18 | }, 19 | "devDependencies": { 20 | "eslint": "^4.14.0", 21 | "eslint-config-prettier": "^2.9.0", 22 | "eslint-plugin-import": "^2.8.0", 23 | "eslint-plugin-jest": "^21.5.0", 24 | "eslint-plugin-prettier": "^2.4.0", 25 | "jest": "^21.1.0", 26 | "jest-runner-eslint": "^0.3.0" 27 | }, 28 | "scripts": { 29 | "lint": "jest -c jest.eslint.config.js", 30 | "test": "jest", 31 | "prettier": "prettier --plugin=. --parser=python" 32 | }, 33 | "jest": { 34 | "projects": ["/jest.*.config.js"] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/_util-from-prettier.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const docBuilders = require("prettier").doc.builders; 4 | 5 | const concat = docBuilders.concat; 6 | const hardline = docBuilders.hardline; 7 | const indent = docBuilders.indent; 8 | const join = docBuilders.join; 9 | 10 | function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) { 11 | const otherQuote = enclosingQuote === '"' ? "'" : '"'; 12 | 13 | // Matches _any_ escape and unescaped quotes (both single and double). 14 | const regex = /\\([\s\S])|(['"])/g; 15 | 16 | // Escape and unescape single and double quotes as needed to be able to 17 | // enclose `rawContent` with `enclosingQuote`. 18 | const newContent = rawContent.replace(regex, (match, escaped, quote) => { 19 | // If we matched an escape, and the escaped character is a quote of the 20 | // other type than we intend to enclose the string with, there's no need for 21 | // it to be escaped, so return it _without_ the backslash. 22 | if (escaped === otherQuote) { 23 | return escaped; 24 | } 25 | 26 | // If we matched an unescaped quote and it is of the _same_ type as we 27 | // intend to enclose the string with, it must be escaped, so return it with 28 | // a backslash. 29 | if (quote === enclosingQuote) { 30 | return "\\" + quote; 31 | } 32 | 33 | if (quote) { 34 | return quote; 35 | } 36 | 37 | // Unescape any unnecessarily escaped character. 38 | // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27 39 | return unescapeUnnecessaryEscapes && 40 | /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) 41 | ? escaped 42 | : "\\" + escaped; 43 | }); 44 | 45 | return enclosingQuote + newContent + enclosingQuote; 46 | } 47 | 48 | function printComment(commentPath, options) { 49 | const comment = commentPath.getValue(); 50 | comment.printed = true; 51 | return options.printer.printComment(commentPath, options); 52 | } 53 | 54 | function printDanglingComments(path, options, sameIndent, filter) { 55 | const parts = []; 56 | const node = path.getValue(); 57 | 58 | if (!node) { 59 | return ""; 60 | } 61 | 62 | if (node.comments) { 63 | path.each(commentPath => { 64 | const comment = commentPath.getValue(); 65 | if ( 66 | comment && 67 | !comment.leading && 68 | !comment.trailing && 69 | (!filter || filter(comment)) 70 | ) { 71 | parts.push(printComment(commentPath, options)); 72 | } 73 | }, "comments"); 74 | } 75 | 76 | if (node.ctx && node.ctx.comments) { 77 | path.each( 78 | commentPath => { 79 | const comment = commentPath.getValue(); 80 | if (comment && (!filter || filter(comment))) { 81 | parts.push(printComment(commentPath, options)); 82 | } 83 | }, 84 | "ctx", 85 | "comments" 86 | ); 87 | } 88 | 89 | if (parts.length === 0) { 90 | return ""; 91 | } 92 | 93 | if (sameIndent) { 94 | return join(hardline, parts); 95 | } 96 | return indent(concat([hardline, join(hardline, parts)])); 97 | } 98 | 99 | module.exports = { 100 | makeString, 101 | printDanglingComments 102 | }; 103 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const utilShared = require("prettier").util; 4 | const util = require("./_util-from-prettier"); 5 | const parse = require("./parser"); 6 | const print = require("./printer"); 7 | 8 | const languages = [ 9 | { 10 | name: "Python", 11 | since: "1.9.2", // FIXME: Fix this before releasing. 12 | parsers: ["python"], 13 | extensions: [".py"], 14 | tmScope: "source.py", 15 | aceMode: "text", 16 | linguistLanguageId: 303, 17 | vscodeLanguageIds: ["python"] 18 | } 19 | ]; 20 | 21 | function locStart(node) { 22 | // This function is copied from the code that used to live in the main prettier repo. 23 | 24 | // Handle nodes with decorators. They should start at the first decorator 25 | if ( 26 | node.declaration && 27 | node.declaration.decorators && 28 | node.declaration.decorators.length > 0 29 | ) { 30 | return locStart(node.declaration.decorators[0]); 31 | } 32 | if (node.decorators && node.decorators.length > 0) { 33 | return locStart(node.decorators[0]); 34 | } 35 | 36 | if (node.__location) { 37 | return node.__location.startOffset; 38 | } 39 | if (node.range) { 40 | return node.range[0]; 41 | } 42 | if (typeof node.start === "number") { 43 | return node.start; 44 | } 45 | if (node.source) { 46 | return ( 47 | utilShared.lineColumnToIndex(node.source.start, node.source.input.css) - 1 48 | ); 49 | } 50 | if (node.loc) { 51 | return node.loc.start; 52 | } 53 | 54 | return 0; 55 | } 56 | 57 | function locEnd(node) { 58 | // This function is copied from the code that used to live in the main prettier repo. 59 | 60 | const endNode = node.nodes && utilShared.getLast(node.nodes); 61 | if (endNode && node.source && !node.source.end) { 62 | node = endNode; 63 | } 64 | 65 | let loc; 66 | if (node.range) { 67 | loc = node.range[1]; 68 | } else if (typeof node.end === "number") { 69 | loc = node.end; 70 | } else if (node.source) { 71 | loc = utilShared.lineColumnToIndex(node.source.end, node.source.input.css); 72 | } 73 | 74 | if (node.__location) { 75 | return node.__location.endOffset; 76 | } 77 | if (node.typeAnnotation) { 78 | return Math.max(loc, locEnd(node.typeAnnotation)); 79 | } 80 | 81 | if (node.loc && !loc) { 82 | return node.loc.end; 83 | } 84 | 85 | return loc || 0; 86 | } 87 | 88 | const parsers = { 89 | python: { 90 | parse, 91 | astFormat: "python", 92 | locStart: locStart, 93 | locEnd: locEnd 94 | } 95 | }; 96 | 97 | const options = { 98 | // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js 99 | pythonVersion: { 100 | since: "0.0.0-development", // FIXME: Fix this before releasing. 101 | category: "Python", 102 | type: "choice", 103 | default: "3", 104 | description: "Which version of Python the code is written for", 105 | choices: [ 106 | { 107 | value: "2", 108 | description: "Python 2" 109 | }, 110 | { 111 | value: "3", 112 | description: "Python 3" 113 | } 114 | ] 115 | } 116 | }; 117 | 118 | function canAttachComment(node) { 119 | return node.ast_type && node.ast_type !== "comment"; 120 | } 121 | 122 | function printComment(commentPath) { 123 | const comment = commentPath.getValue(); 124 | 125 | switch (comment.ast_type) { 126 | case "comment": 127 | return comment.value; 128 | default: 129 | throw new Error("Not a comment: " + JSON.stringify(comment)); 130 | } 131 | } 132 | 133 | function clean(ast, newObj) { 134 | delete newObj.lineno; 135 | delete newObj.col_offset; 136 | } 137 | 138 | const printers = { 139 | python: { 140 | print, 141 | hasPrettierIgnore: util.hasIgnoreComment, 142 | printComment, 143 | canAttachComment, 144 | massageAstNode: clean 145 | } 146 | }; 147 | 148 | module.exports = { 149 | languages, 150 | printers, 151 | parsers, 152 | options, 153 | defaultOptions: { 154 | printWidth: 79, 155 | tabWidth: 4 156 | } 157 | }; 158 | -------------------------------------------------------------------------------- /src/parser.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const spawnSync = require("child_process").spawnSync; 4 | const path = require("path"); 5 | 6 | function parseText(text, pythonExecutable) { 7 | const executionResult = spawnSync( 8 | pythonExecutable, 9 | [path.join(__dirname, "../vendor/python/astexport.py")], 10 | { 11 | input: text 12 | } 13 | ); 14 | 15 | const executionError = executionResult.error; 16 | 17 | if (executionError) { 18 | if (executionError.code === "ENOENT") { 19 | throw new Error(`${pythonExecutable} was not found in your PATH`); 20 | } else { 21 | throw executionError; 22 | } 23 | } 24 | 25 | const error = executionResult.stderr.toString(); 26 | 27 | if (error) { 28 | throw new Error(error); 29 | } 30 | 31 | return executionResult; 32 | } 33 | 34 | function parse(text, parsers, opts) { 35 | const pythonExectuable = `python${opts.pythonVersion == "2" ? "" : "3"}`; 36 | const executionResult = parseText(text, pythonExectuable); 37 | 38 | const res = executionResult.stdout.toString(); 39 | const ast = JSON.parse(res); 40 | return ast; 41 | } 42 | 43 | module.exports = parse; 44 | -------------------------------------------------------------------------------- /src/printer/tokens.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = { 4 | Add: "+", 5 | UAdd: "+", 6 | USub: "-", 7 | Sub: "-", 8 | Mult: "*", 9 | MatMult: "@", 10 | Div: "/", 11 | FloorDiv: "//", 12 | Mod: "%", 13 | Pow: "**", 14 | LShift: "<<", 15 | RShift: ">>", 16 | BitAnd: "&", 17 | BitXor: "^", 18 | BitOr: "|", 19 | Invert: "~", 20 | Lt: "<", 21 | LtE: "<=", 22 | Gt: ">", 23 | GtE: ">=", 24 | Eq: "==", 25 | NotEq: "!=", 26 | In: "in", 27 | NotIn: "not in", 28 | And: "and", 29 | Or: "or", 30 | Not: "not", 31 | Is: "is", 32 | IsNot: "is not", 33 | Pass: "pass", 34 | Continue: "continue", 35 | Break: "break" 36 | }; 37 | -------------------------------------------------------------------------------- /tests/python3_args_mixed/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`args_mixed.py 1`] = ` 4 | def hello(a, *, example=False, **kwargs): 5 | print("hello world", example) 6 | 7 | 8 | def i18n_patterns(*urls, prefix_default_language=True): 9 | pass 10 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 | def hello(a, *, example=False, **kwargs): 12 | print("hello world", example) 13 | 14 | 15 | def i18n_patterns(*urls, prefix_default_language=True): 16 | pass 17 | 18 | `; 19 | -------------------------------------------------------------------------------- /tests/python3_args_mixed/args_mixed.py: -------------------------------------------------------------------------------- 1 | def hello(a, *, example=False, **kwargs): 2 | print("hello world", example) 3 | 4 | 5 | def i18n_patterns(*urls, prefix_default_language=True): 6 | pass 7 | -------------------------------------------------------------------------------- /tests/python3_args_mixed/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { 2 | pythonVersion: "3" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/python3_async_func/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`async_func.py 1`] = ` 4 | async def hello(x, a=123, b = 456): 5 | print("hello world", a) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | async def hello(x, a=123, b=456): 8 | print("hello world", a) 9 | 10 | `; 11 | -------------------------------------------------------------------------------- /tests/python3_async_func/async_func.py: -------------------------------------------------------------------------------- 1 | async def hello(x, a=123, b = 456): 2 | print("hello world", a) 3 | -------------------------------------------------------------------------------- /tests/python3_async_func/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_aug_assign/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`aug_assign.py 1`] = ` 4 | a @= 1 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | a @= 1 7 | 8 | `; 9 | -------------------------------------------------------------------------------- /tests/python3_aug_assign/aug_assign.py: -------------------------------------------------------------------------------- 1 | a @= 1 2 | -------------------------------------------------------------------------------- /tests/python3_aug_assign/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_await/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`await.py 1`] = ` 4 | async def example(): 5 | await channel.put(json.dumps({ 6 | 'text': data.text, 7 | 'image': image, 8 | 'username': data.user.screen_name, 9 | })) 10 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 | async def example(): 12 | await channel.put(json.dumps({ 13 | "text": data.text, 14 | "image": image, 15 | "username": data.user.screen_name 16 | })) 17 | 18 | `; 19 | -------------------------------------------------------------------------------- /tests/python3_await/await.py: -------------------------------------------------------------------------------- 1 | async def example(): 2 | await channel.put(json.dumps({ 3 | 'text': data.text, 4 | 'image': image, 5 | 'username': data.user.screen_name, 6 | })) 7 | -------------------------------------------------------------------------------- /tests/python3_await/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_f_strings/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`f_strings.py 1`] = ` 4 | width = 10 5 | precision = 4 6 | value = decimal.Decimal("12.34567") 7 | f"result: {value:{width}.{precision}}" 8 | rf"result: {value:{width}.{precision}}" 9 | 10 | foo(f'this SHOULD be a multi-line string because it is ' 11 | f'very long and does not fit on one line. And {value} is the value.') 12 | 13 | foo('this SHOULD be a multi-line string, but not reflowed because it is ' 14 | f'very long and and also unusual. And {value} is the value.') 15 | 16 | foo(fR"this should NOT be \\t " 17 | rF'a multi-line string \\n') 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | width = 10 20 | precision = 4 21 | value = decimal.Decimal("12.34567") 22 | f"result: {value:{width}.{precision}}" 23 | rf"result: {value:{width}.{precision}}" 24 | 25 | foo(f'this SHOULD be a multi-line string because it is ' 26 | f'very long and does not fit on one line. And {value} is the value.') 27 | 28 | foo('this SHOULD be a multi-line string, but not reflowed because it is ' 29 | f'very long and and also unusual. And {value} is the value.') 30 | 31 | foo(fR"this should NOT be \\t " 32 | rF'a multi-line string \\n') 33 | 34 | `; 35 | -------------------------------------------------------------------------------- /tests/python3_f_strings/f_strings.py: -------------------------------------------------------------------------------- 1 | width = 10 2 | precision = 4 3 | value = decimal.Decimal("12.34567") 4 | f"result: {value:{width}.{precision}}" 5 | rf"result: {value:{width}.{precision}}" 6 | 7 | foo(f'this SHOULD be a multi-line string because it is ' 8 | f'very long and does not fit on one line. And {value} is the value.') 9 | 10 | foo('this SHOULD be a multi-line string, but not reflowed because it is ' 11 | f'very long and and also unusual. And {value} is the value.') 12 | 13 | foo(fR"this should NOT be \t " 14 | rF'a multi-line string \n') 15 | -------------------------------------------------------------------------------- /tests/python3_f_strings/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_kwargs_only/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`kwargs_only.py 1`] = ` 4 | def hello(a, *, delete=False): 5 | print("hello world", delete) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def hello(a, *, delete=False): 8 | print("hello world", delete) 9 | 10 | `; 11 | -------------------------------------------------------------------------------- /tests/python3_kwargs_only/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_kwargs_only/kwargs_only.py: -------------------------------------------------------------------------------- 1 | def hello(a, *, delete=False): 2 | print("hello world", delete) 3 | -------------------------------------------------------------------------------- /tests/python3_nonlocal/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`nonlocal.py 1`] = ` 4 | x = 0 5 | def outer(): 6 | x = 1 7 | def inner(): 8 | nonlocal x 9 | x = 2 10 | print("inner:", x) 11 | 12 | inner() 13 | print("outer:", x) 14 | 15 | outer() 16 | print("global:", x) 17 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | x = 0 19 | 20 | 21 | def outer(): 22 | x = 1 23 | 24 | def inner(): 25 | nonlocal x 26 | x = 2 27 | print("inner:", x) 28 | 29 | inner() 30 | print("outer:", x) 31 | 32 | 33 | outer() 34 | print("global:", x) 35 | 36 | `; 37 | -------------------------------------------------------------------------------- /tests/python3_nonlocal/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python3_nonlocal/nonlocal.py: -------------------------------------------------------------------------------- 1 | x = 0 2 | def outer(): 3 | x = 1 4 | def inner(): 5 | nonlocal x 6 | x = 2 7 | print("inner:", x) 8 | 9 | inner() 10 | print("outer:", x) 11 | 12 | outer() 13 | print("global:", x) 14 | -------------------------------------------------------------------------------- /tests/python_ann_assign/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`ann_assign.py 1`] = ` 4 | a: str 5 | a: bool = True 6 | 7 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 8 | 9 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = 1 10 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 | a: str 12 | a: bool = True 13 | 14 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: \\ 15 | MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 16 | 17 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: \\ 18 | MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = 1 19 | 20 | `; 21 | -------------------------------------------------------------------------------- /tests/python_ann_assign/ann_assign.py: -------------------------------------------------------------------------------- 1 | a: str 2 | a: bool = True 3 | 4 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 5 | 6 | my_long_var_aaaaaaaaaaaaaaaaaaaaaaaaaa: MyLongTypeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA = 1 7 | -------------------------------------------------------------------------------- /tests/python_ann_assign/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python_arg_annotations/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`args_annotations.py 1`] = ` 4 | class MyThing: 5 | pass 6 | 7 | def hello(a: int, b: str, c: Optional[MyThing]) -> None: 8 | pass 9 | 10 | 11 | def long_annotation(my_long_variable_name_aaaaaaaaaaaaaaaaaaa: MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA) -> None: 12 | pass 13 | 14 | 15 | def ellipses(arg:Tuple[str,...])->Optional[Tuple[str,...]]: 16 | return None 17 | 18 | 19 | def default_args(verbose: bool=False): 20 | pass 21 | 22 | 23 | def annotation_with_long_default( 24 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: MyTypeName = my_long_default_value_aa 25 | ): 26 | pass 27 | 28 | 29 | def long_annotation_with_long_default( 30 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: 31 | MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA = my_long_default_value_aaaaaaaaaaaaaa 32 | ): 33 | pass 34 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35 | class MyThing: 36 | pass 37 | 38 | 39 | def hello(a: int, b: str, c: Optional[MyThing]) -> None: 40 | pass 41 | 42 | 43 | def long_annotation( 44 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: 45 | MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA 46 | ) -> None: 47 | pass 48 | 49 | 50 | def ellipses(arg: Tuple[str, ...]) -> Optional[Tuple[str, ...]]: 51 | return None 52 | 53 | 54 | def default_args(verbose: bool = False): 55 | pass 56 | 57 | 58 | def annotation_with_long_default( 59 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: MyTypeName = 60 | my_long_default_value_aa 61 | ): 62 | pass 63 | 64 | 65 | def long_annotation_with_long_default( 66 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: 67 | MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA = 68 | my_long_default_value_aaaaaaaaaaaaaa 69 | ): 70 | pass 71 | 72 | `; 73 | -------------------------------------------------------------------------------- /tests/python_arg_annotations/args_annotations.py: -------------------------------------------------------------------------------- 1 | class MyThing: 2 | pass 3 | 4 | def hello(a: int, b: str, c: Optional[MyThing]) -> None: 5 | pass 6 | 7 | 8 | def long_annotation(my_long_variable_name_aaaaaaaaaaaaaaaaaaa: MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA) -> None: 9 | pass 10 | 11 | 12 | def ellipses(arg:Tuple[str,...])->Optional[Tuple[str,...]]: 13 | return None 14 | 15 | 16 | def default_args(verbose: bool=False): 17 | pass 18 | 19 | 20 | def annotation_with_long_default( 21 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: MyTypeName = my_long_default_value_aa 22 | ): 23 | pass 24 | 25 | 26 | def long_annotation_with_long_default( 27 | my_long_variable_name_aaaaaaaaaaaaaaaaaaa: 28 | MyLongTypeNameAAAAAAAAAAAAAAAAAAAAA = my_long_default_value_aaaaaaaaaaaaaa 29 | ): 30 | pass 31 | -------------------------------------------------------------------------------- /tests/python_arg_annotations/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python_args/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`args.py 1`] = ` 4 | def hello(*args): 5 | print("hello world", args) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def hello(*args): 8 | print("hello world", args) 9 | 10 | `; 11 | 12 | exports[`args.py 2`] = ` 13 | def hello(*args): 14 | print("hello world", args) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | def hello(*args): 17 | print("hello world", args) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_args/args.py: -------------------------------------------------------------------------------- 1 | def hello(*args): 2 | print("hello world", args) 3 | -------------------------------------------------------------------------------- /tests/python_args/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_args_mixed/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`args_mixed.py 1`] = ` 4 | def hello(a, example=False, **kwargs): 5 | print("hello world", example) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def hello(a, example=False, **kwargs): 8 | print("hello world", example) 9 | 10 | `; 11 | 12 | exports[`args_mixed.py 2`] = ` 13 | def hello(a, example=False, **kwargs): 14 | print("hello world", example) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | def hello(a, example=False, **kwargs): 17 | print("hello world", example) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_args_mixed/args_mixed.py: -------------------------------------------------------------------------------- 1 | def hello(a, example=False, **kwargs): 2 | print("hello world", example) 3 | -------------------------------------------------------------------------------- /tests/python_args_mixed/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_assert/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`assert.py 1`] = ` 4 | assert 3 + 3 5 | assert False, 'message' 6 | 7 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 8 | 9 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, "message" 10 | 11 | assert predicate, "my_long_message_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | assert 3 + 3 14 | assert False, "message" 15 | 16 | assert \\ 17 | my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 18 | 19 | assert \\ 20 | my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, \\ 21 | "message" 22 | 23 | assert predicate, \\ 24 | "my_long_message_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 25 | 26 | `; 27 | 28 | exports[`assert.py 2`] = ` 29 | assert 3 + 3 30 | assert False, 'message' 31 | 32 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 33 | 34 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, "message" 35 | 36 | assert predicate, "my_long_message_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 37 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 38 | assert 3 + 3 39 | assert False, "message" 40 | 41 | assert \\ 42 | my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 43 | 44 | assert \\ 45 | my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, \\ 46 | "message" 47 | 48 | assert predicate, \\ 49 | "my_long_message_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 50 | 51 | `; 52 | -------------------------------------------------------------------------------- /tests/python_assert/assert.py: -------------------------------------------------------------------------------- 1 | assert 3 + 3 2 | assert False, 'message' 3 | 4 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 5 | 6 | assert my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, "message" 7 | 8 | assert predicate, "my_long_message_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 9 | -------------------------------------------------------------------------------- /tests/python_assert/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_assign/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`assign.py 1`] = ` 4 | a = 12 5 | 6 | b = 14 7 | 8 | a, b = b, a 9 | 10 | a = b, c = 1, 2 11 | 12 | a = b = 1, 2 13 | 14 | new_file_name = file_name[:-6] + extension 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | a = 12 17 | 18 | b = 14 19 | 20 | a, b = b, a 21 | 22 | a = b, c = 1, 2 23 | 24 | a = b = (1, 2) 25 | 26 | new_file_name = file_name[:-6] + extension 27 | 28 | `; 29 | 30 | exports[`assign.py 2`] = ` 31 | a = 12 32 | 33 | b = 14 34 | 35 | a, b = b, a 36 | 37 | a = b, c = 1, 2 38 | 39 | a = b = 1, 2 40 | 41 | new_file_name = file_name[:-6] + extension 42 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 | a = 12 44 | 45 | b = 14 46 | 47 | a, b = b, a 48 | 49 | a = b, c = 1, 2 50 | 51 | a = b = (1, 2) 52 | 53 | new_file_name = file_name[:-6] + extension 54 | 55 | `; 56 | -------------------------------------------------------------------------------- /tests/python_assign/assign.py: -------------------------------------------------------------------------------- 1 | a = 12 2 | 3 | b = 14 4 | 5 | a, b = b, a 6 | 7 | a = b, c = 1, 2 8 | 9 | a = b = 1, 2 10 | 11 | new_file_name = file_name[:-6] + extension 12 | -------------------------------------------------------------------------------- /tests/python_assign/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_attributes/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`attributes.py 1`] = ` 4 | query = ( 5 | 'select count(*) from nodes ' 6 | 'where count = {count}' 7 | ).format(count=2) 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | query = ( 10 | 'select count(*) from nodes ' 11 | 'where count = {count}' 12 | ).format(count=2) 13 | 14 | `; 15 | 16 | exports[`attributes.py 2`] = ` 17 | query = ( 18 | 'select count(*) from nodes ' 19 | 'where count = {count}' 20 | ).format(count=2) 21 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | query = ( 23 | 'select count(*) from nodes ' 24 | 'where count = {count}' 25 | ).format(count=2) 26 | 27 | `; 28 | -------------------------------------------------------------------------------- /tests/python_attributes/attributes.py: -------------------------------------------------------------------------------- 1 | query = ( 2 | 'select count(*) from nodes ' 3 | 'where count = {count}' 4 | ).format(count=2) 5 | -------------------------------------------------------------------------------- /tests/python_attributes/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_aug_assign/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`aug_assign.py 1`] = ` 4 | a = 10 5 | 6 | a += 10 7 | 8 | a -= 1 9 | 10 | a *= 1 11 | 12 | a /= 1 13 | 14 | a //= 1 15 | 16 | a %= 1 17 | 18 | a **= 1 19 | 20 | a <<= 1 21 | 22 | a >>= 1 23 | 24 | a &= 1 25 | 26 | a ^= 1 27 | 28 | a |= 1 29 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30 | a = 10 31 | 32 | a += 10 33 | 34 | a -= 1 35 | 36 | a *= 1 37 | 38 | a /= 1 39 | 40 | a //= 1 41 | 42 | a %= 1 43 | 44 | a **= 1 45 | 46 | a <<= 1 47 | 48 | a >>= 1 49 | 50 | a &= 1 51 | 52 | a ^= 1 53 | 54 | a |= 1 55 | 56 | `; 57 | 58 | exports[`aug_assign.py 2`] = ` 59 | a = 10 60 | 61 | a += 10 62 | 63 | a -= 1 64 | 65 | a *= 1 66 | 67 | a /= 1 68 | 69 | a //= 1 70 | 71 | a %= 1 72 | 73 | a **= 1 74 | 75 | a <<= 1 76 | 77 | a >>= 1 78 | 79 | a &= 1 80 | 81 | a ^= 1 82 | 83 | a |= 1 84 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 85 | a = 10 86 | 87 | a += 10 88 | 89 | a -= 1 90 | 91 | a *= 1 92 | 93 | a /= 1 94 | 95 | a //= 1 96 | 97 | a %= 1 98 | 99 | a **= 1 100 | 101 | a <<= 1 102 | 103 | a >>= 1 104 | 105 | a &= 1 106 | 107 | a ^= 1 108 | 109 | a |= 1 110 | 111 | `; 112 | -------------------------------------------------------------------------------- /tests/python_aug_assign/aug_assign.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | 3 | a += 10 4 | 5 | a -= 1 6 | 7 | a *= 1 8 | 9 | a /= 1 10 | 11 | a //= 1 12 | 13 | a %= 1 14 | 15 | a **= 1 16 | 17 | a <<= 1 18 | 19 | a >>= 1 20 | 21 | a &= 1 22 | 23 | a ^= 1 24 | 25 | a |= 1 26 | -------------------------------------------------------------------------------- /tests/python_aug_assign/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_bin_op/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`bin_op.py 1`] = ` 4 | 'LONG_STRING AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s' % my_long_variable_i 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | ( 7 | "LONG_STRING AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s" 8 | % 9 | my_long_variable_i 10 | ) 11 | 12 | `; 13 | 14 | exports[`bin_op.py 2`] = ` 15 | 'LONG_STRING AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s' % my_long_variable_i 16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17 | ( 18 | "LONG_STRING AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s" 19 | % 20 | my_long_variable_i 21 | ) 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_bin_op/bin_op.py: -------------------------------------------------------------------------------- 1 | 'LONG_STRING AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s' % my_long_variable_i 2 | -------------------------------------------------------------------------------- /tests/python_bin_op/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_blank_lines_indented/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`blank_lines_indented.py 1`] = ` 4 | def f(): 5 | a = 1 6 | a = 1 7 | 8 | a = 1 9 | a = 1 10 | 11 | 12 | a = 1 13 | a = 1 14 | 15 | 16 | 17 | a = 1 18 | a = 1 19 | def g(): 20 | pass 21 | 22 | def g(): 23 | pass 24 | 25 | 26 | def g(): 27 | pass 28 | a = 1 29 | 30 | a = 1 31 | class h: 32 | pass 33 | 34 | class h: 35 | pass 36 | 37 | 38 | class h: 39 | pass 40 | a = 1 41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42 | def f(): 43 | a = 1 44 | a = 1 45 | 46 | a = 1 47 | a = 1 48 | 49 | a = 1 50 | a = 1 51 | 52 | a = 1 53 | a = 1 54 | 55 | def g(): 56 | pass 57 | 58 | def g(): 59 | pass 60 | 61 | def g(): 62 | pass 63 | 64 | a = 1 65 | 66 | a = 1 67 | 68 | class h: 69 | pass 70 | 71 | class h: 72 | pass 73 | 74 | class h: 75 | pass 76 | 77 | a = 1 78 | 79 | `; 80 | 81 | 82 | exports[`blank_lines_indented.py 2`] = ` 83 | def f(): 84 | a = 1 85 | a = 1 86 | 87 | a = 1 88 | a = 1 89 | 90 | 91 | a = 1 92 | a = 1 93 | 94 | 95 | 96 | a = 1 97 | a = 1 98 | def g(): 99 | pass 100 | 101 | def g(): 102 | pass 103 | 104 | 105 | def g(): 106 | pass 107 | a = 1 108 | 109 | a = 1 110 | class h: 111 | pass 112 | 113 | class h: 114 | pass 115 | 116 | 117 | class h: 118 | pass 119 | a = 1 120 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 121 | def f(): 122 | a = 1 123 | a = 1 124 | 125 | a = 1 126 | a = 1 127 | 128 | a = 1 129 | a = 1 130 | 131 | a = 1 132 | a = 1 133 | 134 | def g(): 135 | pass 136 | 137 | def g(): 138 | pass 139 | 140 | def g(): 141 | pass 142 | 143 | a = 1 144 | 145 | a = 1 146 | 147 | class h: 148 | pass 149 | 150 | class h: 151 | pass 152 | 153 | class h: 154 | pass 155 | 156 | a = 1 157 | 158 | `; 159 | -------------------------------------------------------------------------------- /tests/python_blank_lines_indented/blank_lines_indented.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | a = 1 3 | a = 1 4 | 5 | a = 1 6 | a = 1 7 | 8 | 9 | a = 1 10 | a = 1 11 | 12 | 13 | 14 | a = 1 15 | a = 1 16 | def g(): 17 | pass 18 | 19 | def g(): 20 | pass 21 | 22 | 23 | def g(): 24 | pass 25 | a = 1 26 | 27 | a = 1 28 | class h: 29 | pass 30 | 31 | class h: 32 | pass 33 | 34 | 35 | class h: 36 | pass 37 | a = 1 38 | -------------------------------------------------------------------------------- /tests/python_blank_lines_indented/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_blank_lines_top_level/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`blank_lines_top_level.py 1`] = ` 4 | import a 5 | import b 6 | 7 | import c 8 | import d 9 | 10 | 11 | import f 12 | A = 1 13 | A = 1 14 | 15 | A = 1 16 | A = 1 17 | 18 | 19 | A = 1 20 | 21 | 22 | 23 | A = 1 24 | def a(): 25 | pass 26 | def a(): 27 | pass 28 | 29 | def a(): 30 | pass 31 | 32 | 33 | 34 | def a(): 35 | pass 36 | A = 1 37 | 38 | 39 | def a(): 40 | pass 41 | 42 | A = 1 43 | 44 | 45 | def a(): 46 | pass 47 | 48 | A = 1 49 | 50 | 51 | def a(): 52 | pass 53 | 54 | 55 | 56 | A = 1 57 | 58 | A = 1 59 | class a: 60 | pass 61 | class a: 62 | pass 63 | 64 | class a: 65 | pass 66 | 67 | 68 | 69 | class a: 70 | pass 71 | A = 1 72 | 73 | 74 | class a: 75 | pass 76 | 77 | A = 1 78 | 79 | 80 | class a: 81 | pass 82 | 83 | A = 1 84 | 85 | 86 | class a: 87 | pass 88 | 89 | 90 | 91 | A = 1 92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93 | import a 94 | import b 95 | 96 | import c 97 | import d 98 | 99 | import f 100 | 101 | A = 1 102 | A = 1 103 | 104 | A = 1 105 | A = 1 106 | 107 | 108 | A = 1 109 | 110 | 111 | A = 1 112 | 113 | 114 | def a(): 115 | pass 116 | 117 | 118 | def a(): 119 | pass 120 | 121 | 122 | def a(): 123 | pass 124 | 125 | 126 | def a(): 127 | pass 128 | 129 | 130 | A = 1 131 | 132 | 133 | def a(): 134 | pass 135 | 136 | 137 | A = 1 138 | 139 | 140 | def a(): 141 | pass 142 | 143 | 144 | A = 1 145 | 146 | 147 | def a(): 148 | pass 149 | 150 | 151 | A = 1 152 | 153 | A = 1 154 | 155 | 156 | class a: 157 | pass 158 | 159 | 160 | class a: 161 | pass 162 | 163 | 164 | class a: 165 | pass 166 | 167 | 168 | class a: 169 | pass 170 | 171 | 172 | A = 1 173 | 174 | 175 | class a: 176 | pass 177 | 178 | 179 | A = 1 180 | 181 | 182 | class a: 183 | pass 184 | 185 | 186 | A = 1 187 | 188 | 189 | class a: 190 | pass 191 | 192 | 193 | A = 1 194 | 195 | `; 196 | 197 | exports[`blank_lines_top_level.py 2`] = ` 198 | import a 199 | import b 200 | 201 | import c 202 | import d 203 | 204 | 205 | import f 206 | A = 1 207 | A = 1 208 | 209 | A = 1 210 | A = 1 211 | 212 | 213 | A = 1 214 | 215 | 216 | 217 | A = 1 218 | def a(): 219 | pass 220 | def a(): 221 | pass 222 | 223 | def a(): 224 | pass 225 | 226 | 227 | 228 | def a(): 229 | pass 230 | A = 1 231 | 232 | 233 | def a(): 234 | pass 235 | 236 | A = 1 237 | 238 | 239 | def a(): 240 | pass 241 | 242 | A = 1 243 | 244 | 245 | def a(): 246 | pass 247 | 248 | 249 | 250 | A = 1 251 | 252 | A = 1 253 | class a: 254 | pass 255 | class a: 256 | pass 257 | 258 | class a: 259 | pass 260 | 261 | 262 | 263 | class a: 264 | pass 265 | A = 1 266 | 267 | 268 | class a: 269 | pass 270 | 271 | A = 1 272 | 273 | 274 | class a: 275 | pass 276 | 277 | A = 1 278 | 279 | 280 | class a: 281 | pass 282 | 283 | 284 | 285 | A = 1 286 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 287 | import a 288 | import b 289 | 290 | import c 291 | import d 292 | 293 | import f 294 | 295 | A = 1 296 | A = 1 297 | 298 | A = 1 299 | A = 1 300 | 301 | 302 | A = 1 303 | 304 | 305 | A = 1 306 | 307 | 308 | def a(): 309 | pass 310 | 311 | 312 | def a(): 313 | pass 314 | 315 | 316 | def a(): 317 | pass 318 | 319 | 320 | def a(): 321 | pass 322 | 323 | 324 | A = 1 325 | 326 | 327 | def a(): 328 | pass 329 | 330 | 331 | A = 1 332 | 333 | 334 | def a(): 335 | pass 336 | 337 | 338 | A = 1 339 | 340 | 341 | def a(): 342 | pass 343 | 344 | 345 | A = 1 346 | 347 | A = 1 348 | 349 | 350 | class a: 351 | pass 352 | 353 | 354 | class a: 355 | pass 356 | 357 | 358 | class a: 359 | pass 360 | 361 | 362 | class a: 363 | pass 364 | 365 | 366 | A = 1 367 | 368 | 369 | class a: 370 | pass 371 | 372 | 373 | A = 1 374 | 375 | 376 | class a: 377 | pass 378 | 379 | 380 | A = 1 381 | 382 | 383 | class a: 384 | pass 385 | 386 | 387 | A = 1 388 | 389 | `; 390 | -------------------------------------------------------------------------------- /tests/python_blank_lines_top_level/blank_lines_top_level.py: -------------------------------------------------------------------------------- 1 | import a 2 | import b 3 | 4 | import c 5 | import d 6 | 7 | 8 | import f 9 | A = 1 10 | A = 1 11 | 12 | A = 1 13 | A = 1 14 | 15 | 16 | A = 1 17 | 18 | 19 | 20 | A = 1 21 | def a(): 22 | pass 23 | def a(): 24 | pass 25 | 26 | def a(): 27 | pass 28 | 29 | 30 | 31 | def a(): 32 | pass 33 | A = 1 34 | 35 | 36 | def a(): 37 | pass 38 | 39 | A = 1 40 | 41 | 42 | def a(): 43 | pass 44 | 45 | A = 1 46 | 47 | 48 | def a(): 49 | pass 50 | 51 | 52 | 53 | A = 1 54 | 55 | A = 1 56 | class a: 57 | pass 58 | class a: 59 | pass 60 | 61 | class a: 62 | pass 63 | 64 | 65 | 66 | class a: 67 | pass 68 | A = 1 69 | 70 | 71 | class a: 72 | pass 73 | 74 | A = 1 75 | 76 | 77 | class a: 78 | pass 79 | 80 | A = 1 81 | 82 | 83 | class a: 84 | pass 85 | 86 | 87 | 88 | A = 1 89 | -------------------------------------------------------------------------------- /tests/python_blank_lines_top_level/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_bool_op/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`bool_op.py 1`] = ` 4 | data.retweeted or 'RT @' in data.text 5 | data.retweeted and 'RT @' in data.text 6 | 7 | my_long_variable_i and my_long_variable_j and 'LONG_STRING' in my_long_variable_i.my_long_attribute_k 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | data.retweeted or "RT @" in data.text 10 | data.retweeted and "RT @" in data.text 11 | 12 | ( 13 | my_long_variable_i and 14 | my_long_variable_j and 15 | "LONG_STRING" in my_long_variable_i.my_long_attribute_k 16 | ) 17 | 18 | `; 19 | 20 | exports[`bool_op.py 2`] = ` 21 | data.retweeted or 'RT @' in data.text 22 | data.retweeted and 'RT @' in data.text 23 | 24 | my_long_variable_i and my_long_variable_j and 'LONG_STRING' in my_long_variable_i.my_long_attribute_k 25 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 | data.retweeted or "RT @" in data.text 27 | data.retweeted and "RT @" in data.text 28 | 29 | ( 30 | my_long_variable_i and 31 | my_long_variable_j and 32 | "LONG_STRING" in my_long_variable_i.my_long_attribute_k 33 | ) 34 | 35 | `; 36 | -------------------------------------------------------------------------------- /tests/python_bool_op/bool_op.py: -------------------------------------------------------------------------------- 1 | data.retweeted or 'RT @' in data.text 2 | data.retweeted and 'RT @' in data.text 3 | 4 | my_long_variable_i and my_long_variable_j and 'LONG_STRING' in my_long_variable_i.my_long_attribute_k 5 | -------------------------------------------------------------------------------- /tests/python_bool_op/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_bytes/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`bytes.py 1`] = ` 4 | b"example" 5 | b'example' 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | b"example" 8 | b"example" 9 | 10 | `; 11 | 12 | exports[`bytes.py 2`] = ` 13 | b"example" 14 | b'example' 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | b'example' 17 | b'example' 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_bytes/bytes.py: -------------------------------------------------------------------------------- 1 | b"example" 2 | b'example' 3 | -------------------------------------------------------------------------------- /tests/python_bytes/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_call/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`call.py 1`] = ` 4 | print(123) 5 | 6 | random.run(123) 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | print(123) 9 | 10 | random.run(123) 11 | 12 | `; 13 | 14 | exports[`call.py 2`] = ` 15 | print(123) 16 | 17 | random.run(123) 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | print(123) 20 | 21 | random.run(123) 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_call/call.py: -------------------------------------------------------------------------------- 1 | print(123) 2 | 3 | random.run(123) 4 | -------------------------------------------------------------------------------- /tests/python_call/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_call_mixed/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`call_mixed.py 1`] = ` 4 | args = (1, 2, 3, 4) 5 | kwargs = {'var_f': 7} 6 | my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs) 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | args = (1, 2, 3, 4) 9 | kwargs = {"var_f": 7} 10 | my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs) 11 | 12 | `; 13 | 14 | exports[`call_mixed.py 2`] = ` 15 | args = (1, 2, 3, 4) 16 | kwargs = {'var_f': 7} 17 | my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs) 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | args = (1, 2, 3, 4) 20 | kwargs = {"var_f": 7} 21 | my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs) 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_call_mixed/call_mixed.py: -------------------------------------------------------------------------------- 1 | args = (1, 2, 3, 4) 2 | kwargs = {'var_f': 7} 3 | my_func_with_many_args(0, *args, var_e=5, var_j=6, **kwargs) 4 | -------------------------------------------------------------------------------- /tests/python_call_mixed/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_class/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`class.py 1`] = ` 4 | class BankAccount(object): 5 | def __init__(self, initial_balance=0): 6 | self.balance = initial_balance 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | class BankAccount(object): 9 | def __init__(self, initial_balance=0): 10 | self.balance = initial_balance 11 | 12 | `; 13 | 14 | exports[`class.py 2`] = ` 15 | class BankAccount(object): 16 | def __init__(self, initial_balance=0): 17 | self.balance = initial_balance 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | class BankAccount(object): 20 | def __init__(self, initial_balance=0): 21 | self.balance = initial_balance 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_class/class.py: -------------------------------------------------------------------------------- 1 | class BankAccount(object): 2 | def __init__(self, initial_balance=0): 3 | self.balance = initial_balance 4 | -------------------------------------------------------------------------------- /tests/python_class/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_comments/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`comments.py 1`] = ` 4 | if a: # a 5 | # b 6 | c 7 | 8 | # c 9 | 10 | d 11 | 12 | # e 13 | 14 | call( 15 | # a 16 | ) 17 | 18 | operations = [ 19 | # Ensure the contenttypes migration is applied before sending 20 | # post_migrate signals (which create ContentTypes). 21 | ] 22 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 | if (a): # a 24 | # b 25 | c 26 | 27 | # c 28 | 29 | d 30 | 31 | # e 32 | 33 | call() 34 | # a 35 | 36 | operations = [ 37 | # Ensure the contenttypes migration is applied before sending 38 | # post_migrate signals (which create ContentTypes). 39 | ] 40 | 41 | `; 42 | 43 | exports[`comments.py 2`] = ` 44 | if a: # a 45 | # b 46 | c 47 | 48 | # c 49 | 50 | d 51 | 52 | # e 53 | 54 | call( 55 | # a 56 | ) 57 | 58 | operations = [ 59 | # Ensure the contenttypes migration is applied before sending 60 | # post_migrate signals (which create ContentTypes). 61 | ] 62 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 63 | if (a): # a 64 | # b 65 | c 66 | 67 | # c 68 | 69 | d 70 | 71 | # e 72 | 73 | call() 74 | # a 75 | 76 | operations = [ 77 | # Ensure the contenttypes migration is applied before sending 78 | # post_migrate signals (which create ContentTypes). 79 | ] 80 | 81 | `; 82 | -------------------------------------------------------------------------------- /tests/python_comments/comments.py: -------------------------------------------------------------------------------- 1 | if a: # a 2 | # b 3 | c 4 | 5 | # c 6 | 7 | d 8 | 9 | # e 10 | 11 | call( 12 | # a 13 | ) 14 | 15 | operations = [ 16 | # Ensure the contenttypes migration is applied before sending 17 | # post_migrate signals (which create ContentTypes). 18 | ] 19 | -------------------------------------------------------------------------------- /tests/python_comments/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_compare/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`compare.py 1`] = ` 4 | x = 10 5 | y = 12 6 | 7 | x < 11 < y < 100 8 | 9 | x > y 10 | 11 | x < y 12 | 13 | x == y 14 | 15 | x != y 16 | 17 | x >= y 18 | 19 | x <= y 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | x = 10 22 | y = 12 23 | 24 | x < 11 < y < 100 25 | 26 | x > y 27 | 28 | x < y 29 | 30 | x == y 31 | 32 | x != y 33 | 34 | x >= y 35 | 36 | x <= y 37 | 38 | `; 39 | 40 | exports[`compare.py 2`] = ` 41 | x = 10 42 | y = 12 43 | 44 | x < 11 < y < 100 45 | 46 | x > y 47 | 48 | x < y 49 | 50 | x == y 51 | 52 | x != y 53 | 54 | x >= y 55 | 56 | x <= y 57 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58 | x = 10 59 | y = 12 60 | 61 | x < 11 < y < 100 62 | 63 | x > y 64 | 65 | x < y 66 | 67 | x == y 68 | 69 | x != y 70 | 71 | x >= y 72 | 73 | x <= y 74 | 75 | `; 76 | -------------------------------------------------------------------------------- /tests/python_compare/compare.py: -------------------------------------------------------------------------------- 1 | x = 10 2 | y = 12 3 | 4 | x < 11 < y < 100 5 | 6 | x > y 7 | 8 | x < y 9 | 10 | x == y 11 | 12 | x != y 13 | 14 | x >= y 15 | 16 | x <= y 17 | -------------------------------------------------------------------------------- /tests/python_compare/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_dangling_comments/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`dangling_comments.py 1`] = ` 4 | # 1 5 | # 2 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | # 1 8 | # 2 9 | 10 | `; 11 | 12 | exports[`dangling_comments.py 2`] = ` 13 | # 1 14 | # 2 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | # 1 17 | # 2 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_dangling_comments/dangling_comments.py: -------------------------------------------------------------------------------- 1 | # 1 2 | # 2 3 | -------------------------------------------------------------------------------- /tests/python_dangling_comments/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_decorators/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`decorators.py 1`] = ` 4 | @Client.event_stream 5 | class UserStream(EventStream): 6 | def stream_request(self): 7 | return self.stream.statuses.filter.post(track="#europython,europython") 8 | 9 | @events.on_connect.handler 10 | @events.on_tweet.handler 11 | def tweet(self, data): 12 | if data.retweeted or 'RT @' in data.text: 13 | return 14 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | @Client.event_stream 16 | class UserStream(EventStream): 17 | def stream_request(self): 18 | return self.stream.statuses.filter.post(track="#europython,europython") 19 | 20 | @events.on_connect.handler 21 | @events.on_tweet.handler 22 | def tweet(self, data): 23 | if data.retweeted or "RT @" in data.text: 24 | return 25 | 26 | `; 27 | 28 | exports[`decorators.py 2`] = ` 29 | @Client.event_stream 30 | class UserStream(EventStream): 31 | def stream_request(self): 32 | return self.stream.statuses.filter.post(track="#europython,europython") 33 | 34 | @events.on_connect.handler 35 | @events.on_tweet.handler 36 | def tweet(self, data): 37 | if data.retweeted or 'RT @' in data.text: 38 | return 39 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 40 | @Client.event_stream 41 | class UserStream(EventStream): 42 | def stream_request(self): 43 | return self.stream.statuses.filter.post(track="#europython,europython") 44 | 45 | @events.on_connect.handler 46 | @events.on_tweet.handler 47 | def tweet(self, data): 48 | if data.retweeted or "RT @" in data.text: 49 | return 50 | 51 | `; 52 | -------------------------------------------------------------------------------- /tests/python_decorators/decorators.py: -------------------------------------------------------------------------------- 1 | @Client.event_stream 2 | class UserStream(EventStream): 3 | def stream_request(self): 4 | return self.stream.statuses.filter.post(track="#europython,europython") 5 | 6 | @events.on_connect.handler 7 | @events.on_tweet.handler 8 | def tweet(self, data): 9 | if data.retweeted or 'RT @' in data.text: 10 | return 11 | -------------------------------------------------------------------------------- /tests/python_decorators/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_default_args/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`default_args.py 1`] = ` 4 | def hello(x, a=123, b = 456): 5 | print("hello world", a) 6 | 7 | 8 | def my_func_with_many_args(self, var_a, var_b, var_c, var_d, var_e=None, var_f=None, 9 | var_g=None, var_h=None, var_i=None, var_j=None): 10 | pass 11 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | def hello(x, a=123, b=456): 13 | print("hello world", a) 14 | 15 | 16 | def my_func_with_many_args( 17 | self, 18 | var_a, 19 | var_b, 20 | var_c, 21 | var_d, 22 | var_e=None, 23 | var_f=None, 24 | var_g=None, 25 | var_h=None, 26 | var_i=None, 27 | var_j=None 28 | ): 29 | pass 30 | 31 | `; 32 | 33 | exports[`default_args.py 2`] = ` 34 | def hello(x, a=123, b = 456): 35 | print("hello world", a) 36 | 37 | 38 | def my_func_with_many_args(self, var_a, var_b, var_c, var_d, var_e=None, var_f=None, 39 | var_g=None, var_h=None, var_i=None, var_j=None): 40 | pass 41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42 | def hello(x, a=123, b=456): 43 | print("hello world", a) 44 | 45 | 46 | def my_func_with_many_args( 47 | self, 48 | var_a, 49 | var_b, 50 | var_c, 51 | var_d, 52 | var_e=None, 53 | var_f=None, 54 | var_g=None, 55 | var_h=None, 56 | var_i=None, 57 | var_j=None 58 | ): 59 | pass 60 | 61 | `; 62 | -------------------------------------------------------------------------------- /tests/python_default_args/default_args.py: -------------------------------------------------------------------------------- 1 | def hello(x, a=123, b = 456): 2 | print("hello world", a) 3 | 4 | 5 | def my_func_with_many_args(self, var_a, var_b, var_c, var_d, var_e=None, var_f=None, 6 | var_g=None, var_h=None, var_i=None, var_j=None): 7 | pass 8 | -------------------------------------------------------------------------------- /tests/python_default_args/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_delete/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`delete.py 1`] = ` 4 | del f.bar 5 | del a 6 | del x[1] 7 | del x['asd'] 8 | del a, b 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | del f.bar 11 | del a 12 | del x[1] 13 | del x["asd"] 14 | del a, b 15 | 16 | `; 17 | 18 | exports[`delete.py 2`] = ` 19 | del f.bar 20 | del a 21 | del x[1] 22 | del x['asd'] 23 | del a, b 24 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 | del f.bar 26 | del a 27 | del x[1] 28 | del x["asd"] 29 | del a, b 30 | 31 | `; 32 | -------------------------------------------------------------------------------- /tests/python_delete/delete.py: -------------------------------------------------------------------------------- 1 | del f.bar 2 | del a 3 | del x[1] 4 | del x['asd'] 5 | del a, b 6 | -------------------------------------------------------------------------------- /tests/python_delete/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_dict/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`dict.py 1`] = ` 4 | a = { 5 | "a": 123, 6 | 'b': 7 | 345 8 | } 9 | 10 | a = { 11 | "a": 123, 12 | 'b': 345, 13 | 'c': 345, 14 | 'd': 345, 15 | 'e': 345, 16 | 'f': 345, 17 | 'g': 345, 18 | 'hhhhhhhhhhhhhh': 19 | 345, 20 | } 21 | 22 | a = { 23 | } 24 | 25 | a = {} 26 | 27 | a = { 28 | 'short_key_1': 1, 29 | 'really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 30 | 'short_key_2': 1, 31 | 'really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 32 | } 33 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 | a = {"a": 123, "b": 345} 35 | 36 | a = { 37 | "a": 123, 38 | "b": 345, 39 | "c": 345, 40 | "d": 345, 41 | "e": 345, 42 | "f": 345, 43 | "g": 345, 44 | "hhhhhhhhhhhhhh": 345 45 | } 46 | 47 | a = {} 48 | 49 | a = {} 50 | 51 | a = { 52 | "short_key_1": 1, 53 | "really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 54 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 55 | "short_key_2": 1, 56 | "really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 57 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 58 | } 59 | 60 | `; 61 | 62 | exports[`dict.py 2`] = ` 63 | a = { 64 | "a": 123, 65 | 'b': 66 | 345 67 | } 68 | 69 | a = { 70 | "a": 123, 71 | 'b': 345, 72 | 'c': 345, 73 | 'd': 345, 74 | 'e': 345, 75 | 'f': 345, 76 | 'g': 345, 77 | 'hhhhhhhhhhhhhh': 78 | 345, 79 | } 80 | 81 | a = { 82 | } 83 | 84 | a = {} 85 | 86 | a = { 87 | 'short_key_1': 1, 88 | 'really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 89 | 'short_key_2': 1, 90 | 'really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 91 | } 92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93 | a = {"a": 123, "b": 345} 94 | 95 | a = { 96 | "a": 123, 97 | "b": 345, 98 | "c": 345, 99 | "d": 345, 100 | "e": 345, 101 | "f": 345, 102 | "g": 345, 103 | "hhhhhhhhhhhhhh": 345, 104 | } 105 | 106 | a = {} 107 | 108 | a = {} 109 | 110 | a = { 111 | "short_key_1": 1, 112 | "really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 113 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 114 | "short_key_2": 1, 115 | "really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 116 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 117 | } 118 | 119 | `; 120 | 121 | exports[`dict.py 3`] = ` 122 | a = { 123 | "a": 123, 124 | 'b': 125 | 345 126 | } 127 | 128 | a = { 129 | "a": 123, 130 | 'b': 345, 131 | 'c': 345, 132 | 'd': 345, 133 | 'e': 345, 134 | 'f': 345, 135 | 'g': 345, 136 | 'hhhhhhhhhhhhhh': 137 | 345, 138 | } 139 | 140 | a = { 141 | } 142 | 143 | a = {} 144 | 145 | a = { 146 | 'short_key_1': 1, 147 | 'really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 148 | 'short_key_2': 1, 149 | 'really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 150 | } 151 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 152 | a = {"a": 123, "b": 345} 153 | 154 | a = { 155 | "a": 123, 156 | "b": 345, 157 | "c": 345, 158 | "d": 345, 159 | "e": 345, 160 | "f": 345, 161 | "g": 345, 162 | "hhhhhhhhhhhhhh": 345 163 | } 164 | 165 | a = {} 166 | 167 | a = {} 168 | 169 | a = { 170 | "short_key_1": 1, 171 | "really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 172 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 173 | "short_key_2": 1, 174 | "really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": 175 | "really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 176 | } 177 | 178 | `; 179 | -------------------------------------------------------------------------------- /tests/python_dict/dict.py: -------------------------------------------------------------------------------- 1 | a = { 2 | "a": 123, 3 | 'b': 4 | 345 5 | } 6 | 7 | a = { 8 | "a": 123, 9 | 'b': 345, 10 | 'c': 345, 11 | 'd': 345, 12 | 'e': 345, 13 | 'f': 345, 14 | 'g': 345, 15 | 'hhhhhhhhhhhhhh': 16 | 345, 17 | } 18 | 19 | a = { 20 | } 21 | 22 | a = {} 23 | 24 | a = { 25 | 'short_key_1': 1, 26 | 'really_long_key_1_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 27 | 'short_key_2': 1, 28 | 'really_long_key_2_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 'really_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 29 | } 30 | -------------------------------------------------------------------------------- /tests/python_dict/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_dict_comp/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`dict_comp.py 1`] = ` 4 | {x: 0 for x in range(100)} 5 | {x: 0 for x in range(100) if x % 2 == 0} 6 | {i: 0 for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0} 7 | {my_long_variable_i: 0 for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0} 8 | 9 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing: 1 for thing in things} 10 | 11 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 12 | 13 | a = {my_long_key_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing): my_long_val_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 14 | 15 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 16 | 17 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | {x: 0 for x in range(100)} 20 | {x: 0 for x in range(100) if x % 2 == 0} 21 | {i: 0 for j in k if j % 2 == 0 if j * 2 < 20 for i in j if i % 2 == 0} 22 | { 23 | my_long_variable_i: 0 24 | for my_long_variable_j in my_long_variable_k 25 | if my_long_variable_j % 2 == 0 26 | if my_long_variable_j * 2 < 20 27 | for my_long_variable_i in my_long_variable_j if my_long_variable_i % 2 == 0 28 | } 29 | 30 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = { 31 | thing: 1 for thing in things 32 | } 33 | 34 | a = { 35 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 36 | for thing in things 37 | } 38 | 39 | a = { 40 | my_long_key_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing): 41 | my_long_val_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 42 | for thing in things 43 | } 44 | 45 | a = { 46 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 47 | for thing in things if thing is not None 48 | } 49 | 50 | a = { 51 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 52 | for thing in things 53 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 54 | } 55 | 56 | `; 57 | 58 | exports[`dict_comp.py 2`] = ` 59 | {x: 0 for x in range(100)} 60 | {x: 0 for x in range(100) if x % 2 == 0} 61 | {i: 0 for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0} 62 | {my_long_variable_i: 0 for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0} 63 | 64 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing: 1 for thing in things} 65 | 66 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 67 | 68 | a = {my_long_key_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing): my_long_val_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 69 | 70 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 71 | 72 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 73 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 | {x: 0 for x in range(100)} 75 | {x: 0 for x in range(100) if x % 2 == 0} 76 | {i: 0 for j in k if j % 2 == 0 if j * 2 < 20 for i in j if i % 2 == 0} 77 | { 78 | my_long_variable_i: 0 79 | for my_long_variable_j in my_long_variable_k 80 | if my_long_variable_j % 2 == 0 81 | if my_long_variable_j * 2 < 20 82 | for my_long_variable_i in my_long_variable_j if my_long_variable_i % 2 == 0 83 | } 84 | 85 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = { 86 | thing: 1 for thing in things 87 | } 88 | 89 | a = { 90 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 91 | for thing in things 92 | } 93 | 94 | a = { 95 | my_long_key_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing): 96 | my_long_val_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 97 | for thing in things 98 | } 99 | 100 | a = { 101 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 102 | for thing in things if thing is not None 103 | } 104 | 105 | a = { 106 | thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 107 | for thing in things 108 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 109 | } 110 | 111 | `; 112 | -------------------------------------------------------------------------------- /tests/python_dict_comp/dict_comp.py: -------------------------------------------------------------------------------- 1 | {x: 0 for x in range(100)} 2 | {x: 0 for x in range(100) if x % 2 == 0} 3 | {i: 0 for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0} 4 | {my_long_variable_i: 0 for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0} 5 | 6 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing: 1 for thing in things} 7 | 8 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 9 | 10 | a = {my_long_key_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing): my_long_val_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 11 | 12 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 13 | 14 | a = {thing: my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 15 | -------------------------------------------------------------------------------- /tests/python_dict_comp/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_elif_multi_body/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`elif_multi_body.py 1`] = ` 4 | if condition: 5 | pass 6 | else: 7 | assert something 8 | another_statement() 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | if condition: 11 | pass 12 | else: 13 | assert something 14 | another_statement() 15 | 16 | `; 17 | -------------------------------------------------------------------------------- /tests/python_elif_multi_body/elif_multi_body.py: -------------------------------------------------------------------------------- 1 | if condition: 2 | pass 3 | else: 4 | assert something 5 | another_statement() 6 | -------------------------------------------------------------------------------- /tests/python_elif_multi_body/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"]); 2 | -------------------------------------------------------------------------------- /tests/python_empty/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`empty_file.py 1`] = ` 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | `; 7 | 8 | exports[`empty_file.py 2`] = ` 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | 11 | `; 12 | 13 | exports[`single_space.py 1`] = ` 14 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | 16 | `; 17 | 18 | exports[`single_space.py 2`] = ` 19 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20 | 21 | `; 22 | -------------------------------------------------------------------------------- /tests/python_empty/empty_file.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prettier/plugin-python/d59dca4b6166dc20eec3e7aa57b0649c072507ce/tests/python_empty/empty_file.py -------------------------------------------------------------------------------- /tests/python_empty/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_empty/single_space.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/python_expressions/expressions.py: -------------------------------------------------------------------------------- 1 | # https://bitbucket.org/pypy/pypy/src/f9e4e9cb7b1949c548cb16ab1520e7ebced75dda/pypy/interpreter/pyparser/test/expressions.py 2 | 3 | 0 4 | 7 5 | -3 6 | # 053 7 | 0x18 8 | # 14L 9 | 1.0 10 | 3.9 11 | -3.6 12 | 1.8e19 13 | 90000000000000 14 | 90000000000000. 15 | 3j 16 | ~3 17 | 18 | x = a + 1 19 | x = 1 - a 20 | x = a * b 21 | x = a ** 2 22 | x = a / b 23 | x = a & b 24 | x = a | b 25 | x = a ^ b 26 | x = a // b 27 | x = a * b + 1 28 | x = a + 1 * b 29 | x = a * b / c 30 | # x = a * (1 + c) 31 | x, y, z = 1, 2, 3 32 | # x = 'a' 'b' 'c' 33 | # del foo 34 | # del foo[bar] 35 | # del foo.bar 36 | l[0] 37 | k[v,] 38 | m[a,b] 39 | a.b.c[d] 40 | file('some.txt').read() 41 | a[0].read() 42 | a[1:1].read() 43 | f('foo')('bar')('spam') 44 | f('foo')('bar')('spam').read()[0] 45 | a.b[0][0] 46 | # a.b[0][:] 47 | # a.b[0][::] 48 | a.b[0][0].pop()[0].push('bar')('baz').spam 49 | a.b[0].read()[1][2].foo().spam()[0].bar 50 | a**2 51 | a**2**2 52 | a.b[0]**2 53 | a.b[0].read()[1][2].foo().spam()[0].bar ** 2 54 | l[start:end] = l2 55 | # l[::] = l2 56 | # a = `s` 57 | # a = `1 + 2 + f(3, 4)` 58 | [a, b] = c 59 | # (a, b) = c 60 | [a, (b,c), d] = e 61 | a, (b, c), d = e 62 | 63 | 1 if True else 2 64 | 1 if False else 2 65 | 66 | l = func() 67 | l = func(10) 68 | # l = func(10, 12, a, b=c, *args) 69 | # l = func(10, 12, a, b=c, **kwargs) 70 | # l = func(10, 12, a, b=c, *args, **kwargs) 71 | l = func(10, 12, a, b=c) 72 | e = l.pop(3) 73 | e = k.l.pop(3) 74 | 75 | l = [] 76 | l = [1, 2, 3] 77 | l = [i for i in range(10)] 78 | l = [i for i in range(10) if i%2 == 0] 79 | l = [i for i in range(10) if i%2 == 0 or i%2 == 1] 80 | l = [i for i in range(10) if i%2 == 0 and i%2 == 1] 81 | l = [i for j in range(10) for i in range(j)] 82 | l = [i for j in range(10) for i in range(j) if j%2 == 0] 83 | l = [i for j in range(10) for i in range(j) if j%2 == 0 and i%2 == 0] 84 | # l = [(a, b) for (a,b,c) in l2] 85 | # l = [{a:b} for (a,b,c) in l2] 86 | # https://github.com/prettier/prettier-python/issues/18 87 | # l = [i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0] 88 | 89 | # l = (i for i in j) 90 | # l = (i for i in j if i%2 == 0) 91 | # l = (i for j in k for i in j) 92 | # l = (i for j in k for i in j if j%2==0) 93 | # l = (i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0) 94 | # l = (i for i in [ j*2 for j in range(10) ] ) 95 | # l = [i for i in ( j*2 for j in range(10) ) ] 96 | # l = (i for i in [ j*2 for j in ( k*3 for k in range(10) ) ] ) 97 | # l = [i for j in ( j*2 for j in [ k*3 for k in range(10) ] ) ] 98 | # l = f(i for i in j) 99 | 100 | l = {a : b, 'c' : 0} 101 | l = {} 102 | 103 | f = lambda x: x+1 104 | f = lambda x,y: x+y 105 | f = lambda x,y=1,z=t: x+y 106 | f = lambda x,y=1,z=t,*args,**kwargs: x+y 107 | f = lambda x,y=1,z=t,*args: x+y 108 | f = lambda x,y=1,z=t,**kwargs: x+y 109 | f = lambda: 1 110 | f = lambda *args: 1 111 | f = lambda **kwargs: 1 112 | 113 | a < b 114 | a > b 115 | a not in b 116 | a is not b 117 | a in b 118 | a is b 119 | not a 120 | # We don't wrap this because it doesn't make sense with a 4-space indent. 121 | not my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 122 | 3 < x < 5 123 | # (3 < x) < 5 124 | a < b < c < d 125 | # (a < b) < (c < d) 126 | # a < (b < c) < d 127 | 128 | a = b; c = d; 129 | # a = b = c = d 130 | 131 | a.b = 2 132 | x = a.b 133 | 134 | # l[:] 135 | # l[::] 136 | l[1:2] 137 | # l[1:] 138 | l[:2] 139 | # l[1::] 140 | # l[:1:] 141 | l[::1] 142 | # l[1:2:] 143 | l[:1:2] 144 | l[1::2] 145 | l[0:1:2] 146 | # a.b.l[:] 147 | a.b.l[1:2] 148 | # a.b.l[1:] 149 | # a.b.l[:2] 150 | a.b.l[0:1:2] 151 | # a[1:2:3, 100] 152 | # a[:2:3, 100] 153 | # a[1::3, 100,] 154 | # a[1:2:, 100] 155 | # a[1:2, 100] 156 | # a[1:, 100,] 157 | # a[:2, 100] 158 | # a[:, 100] 159 | # a[100, 1:2:3,] 160 | # a[100, :2:3] 161 | # a[100, 1::3] 162 | # a[100, 1:2:,] 163 | # a[100, 1:2] 164 | # a[100, 1:] 165 | # a[100, :2,] 166 | # a[100, :] 167 | # 168 | import os 169 | import sys, os 170 | import os.path 171 | import os.path, sys 172 | import sys, os.path as osp 173 | import os.path as osp 174 | import os.path as osp, sys as _sys 175 | import a.b.c.d 176 | import a.b.c.d as abcd 177 | from os import path 178 | from os import path, system 179 | 180 | from os import path, system 181 | from os import path as P, system as S 182 | # from os import (path as P, system as S,) 183 | from os import * 184 | 185 | if a == 1: a+= 2 186 | if a == 1: 187 | a += 2 188 | elif a == 2: 189 | a += 3 190 | else: 191 | a += 4 192 | # if a and not b == c: pass 193 | # if a and not not not b == c: pass 194 | # if 0: print 'foo' 195 | 196 | assert False 197 | assert a == 1 198 | assert a == 1 and b == 2 199 | assert a == 1 and b == 2, "assertion failed" 200 | 201 | # exec a 202 | # exec "a=b+3" 203 | # exec a in f() 204 | # exec a in f(), g() 205 | 206 | # print 207 | # print a 208 | # print a, 209 | # print a, b 210 | # print a, "b", c 211 | # print >> err 212 | # print >> err, "error" 213 | # print >> err, "error", 214 | # print >> err, "error", a 215 | 216 | # global a 217 | # global a,b,c 218 | 219 | raise 220 | raise ValueError 221 | raise ValueError("error") 222 | # raise ValueError, "error" 223 | # raise ValueError, "error", foo 224 | 225 | try: 226 | a 227 | b 228 | except: 229 | pass 230 | try: 231 | a 232 | b 233 | except NameError: 234 | pass 235 | # try: 236 | # a 237 | # b 238 | # except NameError, err: 239 | # pass 240 | # try: 241 | # a 242 | # b 243 | # except (NameError, ValueError): 244 | # pass 245 | # try: 246 | # a 247 | # b 248 | # except (NameError, ValueError), err: 249 | # pass 250 | # try: 251 | # a 252 | # except NameError, err: 253 | # pass 254 | # except ValueError, err: 255 | # pass 256 | # def f(): 257 | # try: 258 | # a 259 | # except NameError, err: 260 | # a = 1 261 | # b = 2 262 | # except ValueError, err: 263 | # a = 2 264 | # return a 265 | # try: 266 | # a 267 | # except NameError, err: 268 | # a = 1 269 | # except ValueError, err: 270 | # a = 2 271 | # else: 272 | # a += 3 273 | # try: 274 | # a 275 | # finally: 276 | # b 277 | # def f(): 278 | # try: 279 | # return a 280 | # finally: 281 | # a = 3 282 | # return 1 283 | 284 | def f(): return 1 285 | def f(x): return x+1 286 | def f(x,y): return x+y 287 | def f(x,y=1,z=t): return x+y 288 | def f(x,y=1,z=t,*args,**kwargs): return x+y 289 | def f(x,y=1,z=t,*args): return x+y 290 | def f(x,y=1,z=t,**kwargs): return x+y 291 | def f(*args): return 1 292 | def f(**kwargs): return 1 293 | # def f(t=()): pass 294 | # def f(a, b, (c, d), e): pass 295 | # def f(a, b, (c, (d, e), f, (g, h))): pass 296 | # def f(a, b, (c, (d, e), f, (g, h)), i): pass 297 | # def f((a)): pass 298 | 299 | class Pdb(bdb.Bdb, cmd.Cmd): pass 300 | class A: pass 301 | 302 | def foo(): return 1 303 | class Foo: pass 304 | class Foo: "foo" 305 | def foo(): 306 | """foo docstring""" 307 | return 1 308 | 309 | def foo(): 310 | """foo docstring""" 311 | a = 1 312 | """bar""" 313 | return a 314 | 315 | # def foo(): 316 | # """doc"""; print 1 317 | # a=1 318 | 319 | # """Docstring""";print 1 320 | 321 | def f(): return 322 | def f(): return 1 323 | def f(): return a.b 324 | def f(): return a 325 | def f(): return a,b,c,d 326 | 327 | a=1;a+=2 328 | a=1;a-=2 329 | a=1;a*=2 330 | a=1;a/=2 331 | a=1;a//=2 332 | a=1;a%=2 333 | a=1;a**=2 334 | a=1;a>>=2 335 | a=1;a<<=2 336 | a=1;a&=2 337 | a=1;a^=2 338 | a=1;a|=2 339 | -------------------------------------------------------------------------------- /tests/python_expressions/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_float/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`float.py 1`] = ` 4 | b = 3.75 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | b = 3.75 7 | 8 | `; 9 | 10 | exports[`float.py 2`] = ` 11 | b = 3.75 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | b = 3.75 14 | 15 | `; 16 | -------------------------------------------------------------------------------- /tests/python_float/float.py: -------------------------------------------------------------------------------- 1 | b = 3.75 2 | -------------------------------------------------------------------------------- /tests/python_float/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_for/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`for.py 1`] = ` 4 | for x in range(10): 5 | print(x) 6 | 7 | for i in ('a', 'e', 'i', 'o', 'u'): 8 | pass 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | for x in range(10): 11 | print(x) 12 | 13 | for i in ("a", "e", "i", "o", "u"): 14 | pass 15 | 16 | `; 17 | 18 | exports[`for.py 2`] = ` 19 | for x in range(10): 20 | print(x) 21 | 22 | for i in ('a', 'e', 'i', 'o', 'u'): 23 | pass 24 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 | for x in range(10): 26 | print(x) 27 | 28 | for i in ("a", "e", "i", "o", "u"): 29 | pass 30 | 31 | `; 32 | -------------------------------------------------------------------------------- /tests/python_for/for.py: -------------------------------------------------------------------------------- 1 | for x in range(10): 2 | print(x) 3 | 4 | for i in ('a', 'e', 'i', 'o', 'u'): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/python_for/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_for_else/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`for_else.py 1`] = ` 4 | for x in range(10): 5 | print(x) 6 | else: 7 | print(x) 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | for x in range(10): 10 | print(x) 11 | else: 12 | print(x) 13 | 14 | `; 15 | 16 | exports[`for_else.py 2`] = ` 17 | for x in range(10): 18 | print(x) 19 | else: 20 | print(x) 21 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | for x in range(10): 23 | print(x) 24 | else: 25 | print(x) 26 | 27 | `; 28 | -------------------------------------------------------------------------------- /tests/python_for_else/for_else.py: -------------------------------------------------------------------------------- 1 | for x in range(10): 2 | print(x) 3 | else: 4 | print(x) 5 | -------------------------------------------------------------------------------- /tests/python_for_else/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_for_kv/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`for_kw.py 1`] = ` 4 | for a, b in [(1, 2), (1, 2)]: 5 | print(a) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | for a, b in [(1, 2), (1, 2)]: 8 | print(a) 9 | 10 | `; 11 | 12 | exports[`for_kw.py 2`] = ` 13 | for a, b in [(1, 2), (1, 2)]: 14 | print(a) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | for a, b in [(1, 2), (1, 2)]: 17 | print(a) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_for_kv/for_kw.py: -------------------------------------------------------------------------------- 1 | for a, b in [(1, 2), (1, 2)]: 2 | print(a) 3 | -------------------------------------------------------------------------------- /tests/python_for_kv/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_generator_expressions/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`generator_expressions.py 1`] = ` 4 | (x for x in range(100)) 5 | (x for x in range(100) if x % 2 == 0) 6 | 7 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (thing for thing in things) 8 | 9 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things) 10 | 11 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None) 12 | 13 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)) 14 | 15 | list(x for x in bar) 16 | 17 | foo((x for x in bar), True) 18 | 19 | foo(True, (x for x in bar)) 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | (x for x in range(100)) 22 | (x for x in range(100) if x % 2 == 0) 23 | 24 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = ( 25 | thing for thing in things 26 | ) 27 | 28 | a = ( 29 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 30 | for thing in things 31 | ) 32 | 33 | a = ( 34 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 35 | for thing in things if thing is not None 36 | ) 37 | 38 | a = ( 39 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 40 | for thing in things 41 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 42 | ) 43 | 44 | list(x for x in bar) 45 | 46 | foo((x for x in bar), True) 47 | 48 | foo(True, (x for x in bar)) 49 | 50 | `; 51 | 52 | exports[`generator_expressions.py 2`] = ` 53 | (x for x in range(100)) 54 | (x for x in range(100) if x % 2 == 0) 55 | 56 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (thing for thing in things) 57 | 58 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things) 59 | 60 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None) 61 | 62 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)) 63 | 64 | list(x for x in bar) 65 | 66 | foo((x for x in bar), True) 67 | 68 | foo(True, (x for x in bar)) 69 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 70 | (x for x in range(100)) 71 | (x for x in range(100) if x % 2 == 0) 72 | 73 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = ( 74 | thing for thing in things 75 | ) 76 | 77 | a = ( 78 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 79 | for thing in things 80 | ) 81 | 82 | a = ( 83 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 84 | for thing in things if thing is not None 85 | ) 86 | 87 | a = ( 88 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 89 | for thing in things 90 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 91 | ) 92 | 93 | list(x for x in bar) 94 | 95 | foo((x for x in bar), True) 96 | 97 | foo(True, (x for x in bar)) 98 | 99 | `; 100 | -------------------------------------------------------------------------------- /tests/python_generator_expressions/generator_expressions.py: -------------------------------------------------------------------------------- 1 | (x for x in range(100)) 2 | (x for x in range(100) if x % 2 == 0) 3 | 4 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (thing for thing in things) 5 | 6 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things) 7 | 8 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None) 9 | 10 | a = (my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)) 11 | 12 | list(x for x in bar) 13 | 14 | foo((x for x in bar), True) 15 | 16 | foo(True, (x for x in bar)) 17 | -------------------------------------------------------------------------------- /tests/python_generator_expressions/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_global/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`global.py 1`] = ` 4 | global a 5 | global b 6 | global a, b 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | global a 9 | global b 10 | global a, b 11 | 12 | `; 13 | 14 | exports[`global.py 2`] = ` 15 | global a 16 | global b 17 | global a, b 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | global a 20 | global b 21 | global a, b 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_global/global.py: -------------------------------------------------------------------------------- 1 | global a 2 | global b 3 | global a, b 4 | -------------------------------------------------------------------------------- /tests/python_global/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_hello/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`hello.py 1`] = ` 4 | def hello(x, y): 5 | print("hello world", x, y) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def hello(x, y): 8 | print("hello world", x, y) 9 | 10 | `; 11 | 12 | exports[`hello.py 2`] = ` 13 | def hello(x, y): 14 | print("hello world", x, y) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | def hello(x, y): 17 | print("hello world", x, y) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_hello/hello.py: -------------------------------------------------------------------------------- 1 | def hello(x, y): 2 | print("hello world", x, y) 3 | -------------------------------------------------------------------------------- /tests/python_hello/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_if/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`if.py 1`] = ` 4 | if x == 'none': 5 | print('None') 6 | elif x == None: 7 | print('oh') 8 | elif x == 12: 9 | print('oh') 10 | else: 11 | print(123) 12 | 13 | if (len(my_long_variable_my_long_variable) == 0 or len(my_long_variable_my_long_variable) == 1): 14 | print("nice") 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | if x == "none": 17 | print("None") 18 | elif x == None: 19 | print("oh") 20 | elif x == 12: 21 | print("oh") 22 | else: 23 | print(123) 24 | 25 | if (len(my_long_variable_my_long_variable) == 0 or 26 | len(my_long_variable_my_long_variable) == 1): 27 | print("nice") 28 | 29 | `; 30 | 31 | exports[`if.py 2`] = ` 32 | if x == 'none': 33 | print('None') 34 | elif x == None: 35 | print('oh') 36 | elif x == 12: 37 | print('oh') 38 | else: 39 | print(123) 40 | 41 | if (len(my_long_variable_my_long_variable) == 0 or len(my_long_variable_my_long_variable) == 1): 42 | print("nice") 43 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 44 | if x == "none": 45 | print("None") 46 | elif x == None: 47 | print("oh") 48 | elif x == 12: 49 | print("oh") 50 | else: 51 | print(123) 52 | 53 | if (len(my_long_variable_my_long_variable) == 0 or 54 | len(my_long_variable_my_long_variable) == 1): 55 | print("nice") 56 | 57 | `; 58 | -------------------------------------------------------------------------------- /tests/python_if/if.py: -------------------------------------------------------------------------------- 1 | if x == 'none': 2 | print('None') 3 | elif x == None: 4 | print('oh') 5 | elif x == 12: 6 | print('oh') 7 | else: 8 | print(123) 9 | 10 | if (len(my_long_variable_my_long_variable) == 0 or len(my_long_variable_my_long_variable) == 1): 11 | print("nice") 12 | -------------------------------------------------------------------------------- /tests/python_if/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_import/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`import.py 1`] = ` 4 | import sys 5 | 6 | from models import X 7 | 8 | from .models import X 9 | 10 | from .models import B as C 11 | 12 | from .example import * 13 | 14 | from ..example import * 15 | 16 | from .. import X 17 | 18 | import long_module_name_1, long_module_name_2, long_module_name_3, long_module_name_4 19 | 20 | from some_module import long_function_name_1, long_function_name_2, long_function_name_3 21 | 22 | import \\ 23 | some_module 24 | 25 | from some_module import ( 26 | some_module, 27 | ) 28 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 29 | import sys 30 | 31 | from models import X 32 | 33 | from .models import X 34 | 35 | from .models import B as C 36 | 37 | from .example import * 38 | 39 | from ..example import * 40 | 41 | from .. import X 42 | 43 | import \\ 44 | long_module_name_1, \\ 45 | long_module_name_2, \\ 46 | long_module_name_3, \\ 47 | long_module_name_4 48 | 49 | from some_module import ( 50 | long_function_name_1, 51 | long_function_name_2, 52 | long_function_name_3 53 | ) 54 | 55 | import some_module 56 | 57 | from some_module import some_module 58 | 59 | `; 60 | 61 | exports[`import.py 2`] = ` 62 | import sys 63 | 64 | from models import X 65 | 66 | from .models import X 67 | 68 | from .models import B as C 69 | 70 | from .example import * 71 | 72 | from ..example import * 73 | 74 | from .. import X 75 | 76 | import long_module_name_1, long_module_name_2, long_module_name_3, long_module_name_4 77 | 78 | from some_module import long_function_name_1, long_function_name_2, long_function_name_3 79 | 80 | import \\ 81 | some_module 82 | 83 | from some_module import ( 84 | some_module, 85 | ) 86 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87 | import sys 88 | 89 | from models import X 90 | 91 | from .models import X 92 | 93 | from .models import B as C 94 | 95 | from .example import * 96 | 97 | from ..example import * 98 | 99 | from .. import X 100 | 101 | import \\ 102 | long_module_name_1, \\ 103 | long_module_name_2, \\ 104 | long_module_name_3, \\ 105 | long_module_name_4 106 | 107 | from some_module import ( 108 | long_function_name_1, 109 | long_function_name_2, 110 | long_function_name_3, 111 | ) 112 | 113 | import some_module 114 | 115 | from some_module import some_module 116 | 117 | `; 118 | 119 | exports[`import.py 3`] = ` 120 | import sys 121 | 122 | from models import X 123 | 124 | from .models import X 125 | 126 | from .models import B as C 127 | 128 | from .example import * 129 | 130 | from ..example import * 131 | 132 | from .. import X 133 | 134 | import long_module_name_1, long_module_name_2, long_module_name_3, long_module_name_4 135 | 136 | from some_module import long_function_name_1, long_function_name_2, long_function_name_3 137 | 138 | import \\ 139 | some_module 140 | 141 | from some_module import ( 142 | some_module, 143 | ) 144 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 145 | import sys 146 | 147 | from models import X 148 | 149 | from .models import X 150 | 151 | from .models import B as C 152 | 153 | from .example import * 154 | 155 | from ..example import * 156 | 157 | from .. import X 158 | 159 | import \\ 160 | long_module_name_1, \\ 161 | long_module_name_2, \\ 162 | long_module_name_3, \\ 163 | long_module_name_4 164 | 165 | from some_module import ( 166 | long_function_name_1, 167 | long_function_name_2, 168 | long_function_name_3 169 | ) 170 | 171 | import some_module 172 | 173 | from some_module import some_module 174 | 175 | `; 176 | -------------------------------------------------------------------------------- /tests/python_import/import.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from models import X 4 | 5 | from .models import X 6 | 7 | from .models import B as C 8 | 9 | from .example import * 10 | 11 | from ..example import * 12 | 13 | from .. import X 14 | 15 | import long_module_name_1, long_module_name_2, long_module_name_3, long_module_name_4 16 | 17 | from some_module import long_function_name_1, long_function_name_2, long_function_name_3 18 | 19 | import \ 20 | some_module 21 | 22 | from some_module import ( 23 | some_module, 24 | ) 25 | -------------------------------------------------------------------------------- /tests/python_import/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_inline_comments/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`inline_comments.py 1`] = ` 4 | message = ( 5 | "hello {}" # comment 6 | ).format("world") 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | message = ( 9 | "hello {}" # comment 10 | ).format("world") 11 | 12 | `; 13 | 14 | exports[`inline_comments.py 2`] = ` 15 | message = ( 16 | "hello {}" # comment 17 | ).format("world") 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | message = ( 20 | "hello {}" # comment 21 | ).format("world") 22 | 23 | `; 24 | -------------------------------------------------------------------------------- /tests/python_inline_comments/inline_comments.py: -------------------------------------------------------------------------------- 1 | message = ( 2 | "hello {}" # comment 3 | ).format("world") 4 | -------------------------------------------------------------------------------- /tests/python_inline_comments/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_kwargs/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`kwargs.py 1`] = ` 4 | def hello(a, **kwargs): 5 | print("hello world", a) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def hello(a, **kwargs): 8 | print("hello world", a) 9 | 10 | `; 11 | 12 | exports[`kwargs.py 2`] = ` 13 | def hello(a, **kwargs): 14 | print("hello world", a) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | def hello(a, **kwargs): 17 | print("hello world", a) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_kwargs/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_kwargs/kwargs.py: -------------------------------------------------------------------------------- 1 | def hello(a, **kwargs): 2 | print("hello world", a) 3 | -------------------------------------------------------------------------------- /tests/python_lambdas/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`lambdas.py 1`] = ` 4 | key=lambda variable: variable[0] 5 | max(lis, key=lambda x:int(x)) 6 | f = lambda param: some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 7 | f = lambda some_very_long_param_name_1_aaaaaaaaaa, some_very_long_param_name_2_aaaaaaaaaa, some_very_long_param_name_3_aaaaaaaaaa: True 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | key = lambda variable: variable[0] 10 | max(lis, key=lambda x: int(x)) 11 | f = lambda param: \\ 12 | some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 13 | f = lambda \\ 14 | some_very_long_param_name_1_aaaaaaaaaa, \\ 15 | some_very_long_param_name_2_aaaaaaaaaa, \\ 16 | some_very_long_param_name_3_aaaaaaaaaa \\ 17 | : \\ 18 | True 19 | 20 | `; 21 | 22 | exports[`lambdas.py 2`] = ` 23 | key=lambda variable: variable[0] 24 | max(lis, key=lambda x:int(x)) 25 | f = lambda param: some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 26 | f = lambda some_very_long_param_name_1_aaaaaaaaaa, some_very_long_param_name_2_aaaaaaaaaa, some_very_long_param_name_3_aaaaaaaaaa: True 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | key = lambda variable: variable[0] 29 | max(lis, key=lambda x: int(x)) 30 | f = lambda param: \\ 31 | some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 32 | f = lambda \\ 33 | some_very_long_param_name_1_aaaaaaaaaa, \\ 34 | some_very_long_param_name_2_aaaaaaaaaa, \\ 35 | some_very_long_param_name_3_aaaaaaaaaa, \\ 36 | : \\ 37 | True 38 | 39 | `; 40 | 41 | exports[`lambdas.py 3`] = ` 42 | key=lambda variable: variable[0] 43 | max(lis, key=lambda x:int(x)) 44 | f = lambda param: some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 45 | f = lambda some_very_long_param_name_1_aaaaaaaaaa, some_very_long_param_name_2_aaaaaaaaaa, some_very_long_param_name_3_aaaaaaaaaa: True 46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 | key = lambda variable: variable[0] 48 | max(lis, key=lambda x: int(x)) 49 | f = lambda param: \\ 50 | some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 51 | f = lambda \\ 52 | some_very_long_param_name_1_aaaaaaaaaa, \\ 53 | some_very_long_param_name_2_aaaaaaaaaa, \\ 54 | some_very_long_param_name_3_aaaaaaaaaa \\ 55 | : \\ 56 | True 57 | 58 | `; 59 | -------------------------------------------------------------------------------- /tests/python_lambdas/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_lambdas/lambdas.py: -------------------------------------------------------------------------------- 1 | key=lambda variable: variable[0] 2 | max(lis, key=lambda x:int(x)) 3 | f = lambda param: some_very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 4 | f = lambda some_very_long_param_name_1_aaaaaaaaaa, some_very_long_param_name_2_aaaaaaaaaa, some_very_long_param_name_3_aaaaaaaaaa: True 5 | -------------------------------------------------------------------------------- /tests/python_list/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`list.py 1`] = ` 4 | a = [ 5 | "a", 6 | 'b' 7 | ] 8 | 9 | a = [ 10 | "a", 11 | 'b', 12 | 'c', 13 | 'd', 14 | 'e', 15 | 'f', 16 | 'g', 17 | 'hhhhhhhhhhhhhh', 18 | ] 19 | 20 | a = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'] 21 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | a = ["a", "b"] 23 | 24 | a = ["a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"] 25 | 26 | a = [ 27 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 28 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 29 | "cccccccccccccccccccccccccccc", 30 | "dddddddddddddddddddddddddddd" 31 | ] 32 | 33 | `; 34 | 35 | exports[`list.py 2`] = ` 36 | a = [ 37 | "a", 38 | 'b' 39 | ] 40 | 41 | a = [ 42 | "a", 43 | 'b', 44 | 'c', 45 | 'd', 46 | 'e', 47 | 'f', 48 | 'g', 49 | 'hhhhhhhhhhhhhh', 50 | ] 51 | 52 | a = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'] 53 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 | a = ["a", "b"] 55 | 56 | a = ["a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"] 57 | 58 | a = [ 59 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 60 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 61 | "cccccccccccccccccccccccccccc", 62 | "dddddddddddddddddddddddddddd", 63 | ] 64 | 65 | `; 66 | 67 | exports[`list.py 3`] = ` 68 | a = [ 69 | "a", 70 | 'b' 71 | ] 72 | 73 | a = [ 74 | "a", 75 | 'b', 76 | 'c', 77 | 'd', 78 | 'e', 79 | 'f', 80 | 'g', 81 | 'hhhhhhhhhhhhhh', 82 | ] 83 | 84 | a = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'] 85 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 86 | a = ["a", "b"] 87 | 88 | a = ["a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"] 89 | 90 | a = [ 91 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 92 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 93 | "cccccccccccccccccccccccccccc", 94 | "dddddddddddddddddddddddddddd" 95 | ] 96 | 97 | `; 98 | -------------------------------------------------------------------------------- /tests/python_list/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_list/list.py: -------------------------------------------------------------------------------- 1 | a = [ 2 | "a", 3 | 'b' 4 | ] 5 | 6 | a = [ 7 | "a", 8 | 'b', 9 | 'c', 10 | 'd', 11 | 'e', 12 | 'f', 13 | 'g', 14 | 'hhhhhhhhhhhhhh', 15 | ] 16 | 17 | a = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'] 18 | -------------------------------------------------------------------------------- /tests/python_list_comp/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`list_comp.py 1`] = ` 4 | [x for x in range(100)] 5 | [x for x in range(100) if x % 2 == 0] 6 | [i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0] 7 | [my_long_variable_i for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0] 8 | 9 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = [thing for thing in things] 10 | 11 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things] 12 | 13 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None] 14 | 15 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)] 16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17 | [x for x in range(100)] 18 | [x for x in range(100) if x % 2 == 0] 19 | [i for j in k if j % 2 == 0 if j * 2 < 20 for i in j if i % 2 == 0] 20 | [ 21 | my_long_variable_i 22 | for my_long_variable_j in my_long_variable_k 23 | if my_long_variable_j % 2 == 0 24 | if my_long_variable_j * 2 < 20 25 | for my_long_variable_i in my_long_variable_j if my_long_variable_i % 2 == 0 26 | ] 27 | 28 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = [ 29 | thing for thing in things 30 | ] 31 | 32 | a = [ 33 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 34 | for thing in things 35 | ] 36 | 37 | a = [ 38 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 39 | for thing in things if thing is not None 40 | ] 41 | 42 | a = [ 43 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 44 | for thing in things 45 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 46 | ] 47 | 48 | `; 49 | 50 | exports[`list_comp.py 2`] = ` 51 | [x for x in range(100)] 52 | [x for x in range(100) if x % 2 == 0] 53 | [i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0] 54 | [my_long_variable_i for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0] 55 | 56 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = [thing for thing in things] 57 | 58 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things] 59 | 60 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None] 61 | 62 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)] 63 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 64 | [x for x in range(100)] 65 | [x for x in range(100) if x % 2 == 0] 66 | [i for j in k if j % 2 == 0 if j * 2 < 20 for i in j if i % 2 == 0] 67 | [ 68 | my_long_variable_i 69 | for my_long_variable_j in my_long_variable_k 70 | if my_long_variable_j % 2 == 0 71 | if my_long_variable_j * 2 < 20 72 | for my_long_variable_i in my_long_variable_j if my_long_variable_i % 2 == 0 73 | ] 74 | 75 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = [ 76 | thing for thing in things 77 | ] 78 | 79 | a = [ 80 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 81 | for thing in things 82 | ] 83 | 84 | a = [ 85 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 86 | for thing in things if thing is not None 87 | ] 88 | 89 | a = [ 90 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 91 | for thing in things 92 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 93 | ] 94 | 95 | `; 96 | -------------------------------------------------------------------------------- /tests/python_list_comp/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_list_comp/list_comp.py: -------------------------------------------------------------------------------- 1 | [x for x in range(100)] 2 | [x for x in range(100) if x % 2 == 0] 3 | [i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0] 4 | [my_long_variable_i for my_long_variable_j in my_long_variable_k if my_long_variable_j%2 == 0 if my_long_variable_j*2 < 20 for my_long_variable_i in my_long_variable_j if my_long_variable_i%2==0] 5 | 6 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = [thing for thing in things] 7 | 8 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things] 9 | 10 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None] 11 | 12 | a = [my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)] 13 | -------------------------------------------------------------------------------- /tests/python_long/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`hello.py 1`] = ` 4 | def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): 5 | print("hello world", this_is_another_long_parameter) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | def this_is_a_long_function( 8 | this_is_a_long_parameter, 9 | this_is_another_long_parameter 10 | ): 11 | print("hello world", this_is_another_long_parameter) 12 | 13 | `; 14 | 15 | exports[`hello.py 2`] = ` 16 | def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): 17 | print("hello world", this_is_another_long_parameter) 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | def this_is_a_long_function( 20 | this_is_a_long_parameter, 21 | this_is_another_long_parameter, 22 | ): 23 | print("hello world", this_is_another_long_parameter) 24 | 25 | `; 26 | 27 | exports[`hello.py 3`] = ` 28 | def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): 29 | print("hello world", this_is_another_long_parameter) 30 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 31 | def this_is_a_long_function( 32 | this_is_a_long_parameter, 33 | this_is_another_long_parameter 34 | ): 35 | print("hello world", this_is_another_long_parameter) 36 | 37 | `; 38 | -------------------------------------------------------------------------------- /tests/python_long/hello.py: -------------------------------------------------------------------------------- 1 | def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): 2 | print("hello world", this_is_another_long_parameter) 3 | -------------------------------------------------------------------------------- /tests/python_long/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_nested_if/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`nested_if.py 1`] = ` 4 | if x == 'none': 5 | if False: 6 | print('None') 7 | elif x == None: 8 | print('oh') 9 | elif x == 12: 10 | print('oh') 11 | else: 12 | print(123) 13 | 14 | if foo: 15 | foo() 16 | elif bar: 17 | bar() 18 | else: 19 | if baz: 20 | baz() 21 | elif garply: 22 | garply() 23 | else: 24 | qux() 25 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 | if x == "none": 27 | if False: 28 | print("None") 29 | elif x == None: 30 | print("oh") 31 | elif x == 12: 32 | print("oh") 33 | else: 34 | print(123) 35 | 36 | if foo: 37 | foo() 38 | elif bar: 39 | bar() 40 | elif baz: 41 | baz() 42 | elif garply: 43 | garply() 44 | else: 45 | qux() 46 | 47 | `; 48 | 49 | exports[`nested_if.py 2`] = ` 50 | if x == 'none': 51 | if False: 52 | print('None') 53 | elif x == None: 54 | print('oh') 55 | elif x == 12: 56 | print('oh') 57 | else: 58 | print(123) 59 | 60 | if foo: 61 | foo() 62 | elif bar: 63 | bar() 64 | else: 65 | if baz: 66 | baz() 67 | elif garply: 68 | garply() 69 | else: 70 | qux() 71 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 | if x == "none": 73 | if False: 74 | print("None") 75 | elif x == None: 76 | print("oh") 77 | elif x == 12: 78 | print("oh") 79 | else: 80 | print(123) 81 | 82 | if foo: 83 | foo() 84 | elif bar: 85 | bar() 86 | elif baz: 87 | baz() 88 | elif garply: 89 | garply() 90 | else: 91 | qux() 92 | 93 | `; 94 | -------------------------------------------------------------------------------- /tests/python_nested_if/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_nested_if/nested_if.py: -------------------------------------------------------------------------------- 1 | if x == 'none': 2 | if False: 3 | print('None') 4 | elif x == None: 5 | print('oh') 6 | elif x == 12: 7 | print('oh') 8 | else: 9 | print(123) 10 | 11 | if foo: 12 | foo() 13 | elif bar: 14 | bar() 15 | else: 16 | if baz: 17 | baz() 18 | elif garply: 19 | garply() 20 | else: 21 | qux() 22 | -------------------------------------------------------------------------------- /tests/python_not_in/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`not_in.py 1`] = ` 4 | a not in x 5 | a not in [1, 2] 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | a not in x 8 | a not in [1, 2] 9 | 10 | `; 11 | 12 | exports[`not_in.py 2`] = ` 13 | a not in x 14 | a not in [1, 2] 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | a not in x 17 | a not in [1, 2] 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_not_in/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_not_in/not_in.py: -------------------------------------------------------------------------------- 1 | a not in x 2 | a not in [1, 2] 3 | -------------------------------------------------------------------------------- /tests/python_pass/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`pass.py 1`] = ` 4 | class Client: 5 | pass 6 | 7 | def x(): pass 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | class Client: 10 | pass 11 | 12 | 13 | def x(): 14 | pass 15 | 16 | `; 17 | 18 | exports[`pass.py 2`] = ` 19 | class Client: 20 | pass 21 | 22 | def x(): pass 23 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 | class Client: 25 | pass 26 | 27 | 28 | def x(): 29 | pass 30 | 31 | `; 32 | -------------------------------------------------------------------------------- /tests/python_pass/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_pass/pass.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | pass 3 | 4 | def x(): pass 5 | -------------------------------------------------------------------------------- /tests/python_print_width/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`print_width.py 1`] = ` 4 | def foo(): 5 | return "line_with_79_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 6 | return "line_with_80_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | def foo(): 9 | return "line_with_79_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 10 | return ( 11 | "line_with_80_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 12 | ) 13 | 14 | `; 15 | 16 | exports[`print_width.py 2`] = ` 17 | def foo(): 18 | return "line_with_79_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 19 | return "line_with_80_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 20 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21 | def foo(): 22 | return "line_with_79_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 23 | return ( 24 | "line_with_80_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 25 | ) 26 | 27 | `; 28 | -------------------------------------------------------------------------------- /tests/python_print_width/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_print_width/print_width.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | return "line_with_79_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 3 | return "line_with_80_chars_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 4 | -------------------------------------------------------------------------------- /tests/python_raise/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`raise.py 1`] = ` 4 | raise 5 | raise ValueError 6 | raise ValueError("error") 7 | 8 | raise NotImplementedError('example.') 9 | 10 | raise forms.ValidationError( 11 | self.error_messages['invalid_login'], 12 | code='invalid_login', 13 | params={ 14 | 'username': self.username_field.verbose_name 15 | } 16 | ) 17 | 18 | raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks() 19 | 20 | raise NotImplementedError( 21 | 'The SimpleListFilter.lookups() method must be overridden to ' 22 | 'return a list of tuples (value, verbose value).' 23 | ) 24 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 | raise 26 | raise ValueError 27 | raise ValueError("error") 28 | 29 | raise NotImplementedError("example.") 30 | 31 | raise ( 32 | forms.ValidationError(self.error_messages[ 33 | "invalid_login" 34 | ], code="invalid_login", params={ 35 | "username": self.username_field.verbose_name 36 | }) 37 | ) 38 | 39 | raise ( 40 | SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks() 41 | ) 42 | 43 | raise ( 44 | NotImplementedError('The SimpleListFilter.lookups() method must be overridden to ' 45 | 'return a list of tuples (value, verbose value).') 46 | ) 47 | 48 | `; 49 | 50 | exports[`raise.py 2`] = ` 51 | raise 52 | raise ValueError 53 | raise ValueError("error") 54 | 55 | raise NotImplementedError('example.') 56 | 57 | raise forms.ValidationError( 58 | self.error_messages['invalid_login'], 59 | code='invalid_login', 60 | params={ 61 | 'username': self.username_field.verbose_name 62 | } 63 | ) 64 | 65 | raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks() 66 | 67 | raise NotImplementedError( 68 | 'The SimpleListFilter.lookups() method must be overridden to ' 69 | 'return a list of tuples (value, verbose value).' 70 | ) 71 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 | raise 73 | raise ValueError 74 | raise ValueError("error") 75 | 76 | raise NotImplementedError("example.") 77 | 78 | raise ( 79 | forms.ValidationError(self.error_messages[ 80 | "invalid_login" 81 | ], code="invalid_login", params={ 82 | "username": self.username_field.verbose_name 83 | }) 84 | ) 85 | 86 | raise ( 87 | SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks() 88 | ) 89 | 90 | raise ( 91 | NotImplementedError('The SimpleListFilter.lookups() method must be overridden to ' 92 | 'return a list of tuples (value, verbose value).') 93 | ) 94 | 95 | `; 96 | -------------------------------------------------------------------------------- /tests/python_raise/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_raise/raise.py: -------------------------------------------------------------------------------- 1 | raise 2 | raise ValueError 3 | raise ValueError("error") 4 | 5 | raise NotImplementedError('example.') 6 | 7 | raise forms.ValidationError( 8 | self.error_messages['invalid_login'], 9 | code='invalid_login', 10 | params={ 11 | 'username': self.username_field.verbose_name 12 | } 13 | ) 14 | 15 | raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks() 16 | 17 | raise NotImplementedError( 18 | 'The SimpleListFilter.lookups() method must be overridden to ' 19 | 'return a list of tuples (value, verbose value).' 20 | ) 21 | -------------------------------------------------------------------------------- /tests/python_return/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`return.py 1`] = ` 4 | def example(first): 5 | if False: 6 | return 7 | 8 | return first 9 | 10 | 11 | def foo(): 12 | return my_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 13 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14 | def example(first): 15 | if False: 16 | return 17 | 18 | return first 19 | 20 | 21 | def foo(): 22 | return \\ 23 | my_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 24 | 25 | `; 26 | 27 | exports[`return.py 2`] = ` 28 | def example(first): 29 | if False: 30 | return 31 | 32 | return first 33 | 34 | 35 | def foo(): 36 | return my_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 37 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 38 | def example(first): 39 | if False: 40 | return 41 | 42 | return first 43 | 44 | 45 | def foo(): 46 | return \\ 47 | my_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 48 | 49 | `; 50 | -------------------------------------------------------------------------------- /tests/python_return/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_return/return.py: -------------------------------------------------------------------------------- 1 | def example(first): 2 | if False: 3 | return 4 | 5 | return first 6 | 7 | 8 | def foo(): 9 | return my_long_value_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 10 | -------------------------------------------------------------------------------- /tests/python_set/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`set.py 1`] = ` 4 | a = { 5 | "a", 6 | 'b' 7 | } 8 | 9 | a = { 10 | "a", 11 | 'b', 12 | 'c', 13 | 'd', 14 | 'e', 15 | 'f', 16 | 'g', 17 | 'hhhhhhhhhhhhhh', 18 | } 19 | 20 | a = {'aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'} 21 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | a = {"a", "b"} 23 | 24 | a = {"a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"} 25 | 26 | a = { 27 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 28 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 29 | "cccccccccccccccccccccccccccc", 30 | "dddddddddddddddddddddddddddd" 31 | } 32 | 33 | `; 34 | 35 | exports[`set.py 2`] = ` 36 | a = { 37 | "a", 38 | 'b' 39 | } 40 | 41 | a = { 42 | "a", 43 | 'b', 44 | 'c', 45 | 'd', 46 | 'e', 47 | 'f', 48 | 'g', 49 | 'hhhhhhhhhhhhhh', 50 | } 51 | 52 | a = {'aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'} 53 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 | a = {"a", "b"} 55 | 56 | a = {"a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"} 57 | 58 | a = { 59 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 60 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 61 | "cccccccccccccccccccccccccccc", 62 | "dddddddddddddddddddddddddddd", 63 | } 64 | 65 | `; 66 | 67 | exports[`set.py 3`] = ` 68 | a = { 69 | "a", 70 | 'b' 71 | } 72 | 73 | a = { 74 | "a", 75 | 'b', 76 | 'c', 77 | 'd', 78 | 'e', 79 | 'f', 80 | 'g', 81 | 'hhhhhhhhhhhhhh', 82 | } 83 | 84 | a = {'aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'} 85 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 86 | a = {"a", "b"} 87 | 88 | a = {"a", "b", "c", "d", "e", "f", "g", "hhhhhhhhhhhhhh"} 89 | 90 | a = { 91 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 92 | "bbbbbbbbbbbbbbbbbbbbbbbbbbbb", 93 | "cccccccccccccccccccccccccccc", 94 | "dddddddddddddddddddddddddddd" 95 | } 96 | 97 | `; 98 | -------------------------------------------------------------------------------- /tests/python_set/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_set/set.py: -------------------------------------------------------------------------------- 1 | a = { 2 | "a", 3 | 'b' 4 | } 5 | 6 | a = { 7 | "a", 8 | 'b', 9 | 'c', 10 | 'd', 11 | 'e', 12 | 'f', 13 | 'g', 14 | 'hhhhhhhhhhhhhh', 15 | } 16 | 17 | a = {'aaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccc', 'dddddddddddddddddddddddddddd'} 18 | -------------------------------------------------------------------------------- /tests/python_set_comp/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`set_comp.py 1`] = ` 4 | {x for x in range(100)} 5 | {x for x in range(100) if x % 2 == 0} 6 | 7 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing for thing in things} 8 | 9 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 10 | 11 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 12 | 13 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 14 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | {x for x in range(100)} 16 | {x for x in range(100) if x % 2 == 0} 17 | 18 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = { 19 | thing for thing in things 20 | } 21 | 22 | a = { 23 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 24 | for thing in things 25 | } 26 | 27 | a = { 28 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 29 | for thing in things if thing is not None 30 | } 31 | 32 | a = { 33 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 34 | for thing in things 35 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 36 | } 37 | 38 | `; 39 | 40 | exports[`set_comp.py 2`] = ` 41 | {x for x in range(100)} 42 | {x for x in range(100) if x % 2 == 0} 43 | 44 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing for thing in things} 45 | 46 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 47 | 48 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 49 | 50 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 51 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 | {x for x in range(100)} 53 | {x for x in range(100) if x % 2 == 0} 54 | 55 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = { 56 | thing for thing in things 57 | } 58 | 59 | a = { 60 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 61 | for thing in things 62 | } 63 | 64 | a = { 65 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 66 | for thing in things if thing is not None 67 | } 68 | 69 | a = { 70 | my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 71 | for thing in things 72 | if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) 73 | } 74 | 75 | `; 76 | -------------------------------------------------------------------------------- /tests/python_set_comp/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_set_comp/set_comp.py: -------------------------------------------------------------------------------- 1 | {x for x in range(100)} 2 | {x for x in range(100) if x % 2 == 0} 3 | 4 | my_long_variable_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = {thing for thing in things} 5 | 6 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things} 7 | 8 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if thing is not None} 9 | 10 | a = {my_long_function_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing) for thing in things if my_long_predicate_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(thing)} 11 | -------------------------------------------------------------------------------- /tests/python_slices/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`list.py 1`] = ` 4 | a[-1] 5 | a[-2:] 6 | a[:-2] 7 | a[::-1] 8 | a[1::-1] 9 | a[:-3:-1] 10 | a[-3::-1] 11 | point_coords = coords[i, :] 12 | main(sys.argv[1:]) 13 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14 | a[-1] 15 | a[-2:] 16 | a[:-2] 17 | a[::-1] 18 | a[1::-1] 19 | a[:-3:-1] 20 | a[-3::-1] 21 | point_coords = coords[i, :] 22 | main(sys.argv[1:]) 23 | 24 | `; 25 | 26 | exports[`list.py 2`] = ` 27 | a[-1] 28 | a[-2:] 29 | a[:-2] 30 | a[::-1] 31 | a[1::-1] 32 | a[:-3:-1] 33 | a[-3::-1] 34 | point_coords = coords[i, :] 35 | main(sys.argv[1:]) 36 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | a[-1] 38 | a[-2:] 39 | a[:-2] 40 | a[::-1] 41 | a[1::-1] 42 | a[:-3:-1] 43 | a[-3::-1] 44 | point_coords = coords[i, :] 45 | main(sys.argv[1:]) 46 | 47 | `; 48 | 49 | exports[`list.py 3`] = ` 50 | a[-1] 51 | a[-2:] 52 | a[:-2] 53 | a[::-1] 54 | a[1::-1] 55 | a[:-3:-1] 56 | a[-3::-1] 57 | point_coords = coords[i, :] 58 | main(sys.argv[1:]) 59 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | a[-1] 61 | a[-2:] 62 | a[:-2] 63 | a[::-1] 64 | a[1::-1] 65 | a[:-3:-1] 66 | a[-3::-1] 67 | point_coords = coords[i, :] 68 | main(sys.argv[1:]) 69 | 70 | `; 71 | -------------------------------------------------------------------------------- /tests/python_slices/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_slices/list.py: -------------------------------------------------------------------------------- 1 | a[-1] 2 | a[-2:] 3 | a[:-2] 4 | a[::-1] 5 | a[1::-1] 6 | a[:-3:-1] 7 | a[-3::-1] 8 | point_coords = coords[i, :] 9 | main(sys.argv[1:]) 10 | -------------------------------------------------------------------------------- /tests/python_starred/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`starred.py 1`] = ` 4 | func(*args, **kwargs) 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | func(*args, **kwargs) 7 | 8 | `; 9 | 10 | exports[`starred.py 2`] = ` 11 | func(*args, **kwargs) 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | func(*args, **kwargs) 14 | 15 | `; 16 | -------------------------------------------------------------------------------- /tests/python_starred/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_starred/starred.py: -------------------------------------------------------------------------------- 1 | func(*args, **kwargs) 2 | -------------------------------------------------------------------------------- /tests/python_str_token/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`str_token.py 1`] = ` 4 | _srid_cache = defaultdict(dict) 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 | _srid_cache = defaultdict(dict) 7 | 8 | `; 9 | 10 | exports[`str_token.py 2`] = ` 11 | _srid_cache = defaultdict(dict) 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | _srid_cache = defaultdict(dict) 14 | 15 | `; 16 | -------------------------------------------------------------------------------- /tests/python_str_token/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_str_token/str_token.py: -------------------------------------------------------------------------------- 1 | _srid_cache = defaultdict(dict) 2 | -------------------------------------------------------------------------------- /tests/python_strings/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`strings.py 1`] = ` 4 | a = "it is \\"ok\\"" 5 | a = "it is 'ok'" 6 | a = 'it is \\'ok\\'' 7 | a = 'it is "ok"' 8 | 9 | a = """this is a multiline 10 | string""" 11 | b = '''another multiline 12 | string''' 13 | 14 | a = "both 'single' and \\"double\\"" 15 | a = 'both \\'single\\' and "double"' 16 | 17 | a = u"unicode snowman: \\u26C4" 18 | a = r"this does not have a tab: \\t" 19 | a = b"here's some bytes" 20 | 21 | a = '''escaped triple quote \\''' in middle''' 22 | a = """escaped triple quote \\""" in middle""" 23 | 24 | a = """other triple quote ''' in the middle""" 25 | a = '''other triple quote """ in the middle''' 26 | 27 | a = ("this SHOULD be re-flowed, but still a multi-line string " 28 | "because it is very long and does not fit on one line") 29 | 30 | # The interior triple quotes don't get escaped properly 31 | # a = '''both triple quotes """ and \\''' in the middle''' 32 | # a = """both triple quotes ''' and \\""" in the middle""" 33 | 34 | # In the future these might be re-flowed, if that's a feature we want to 35 | # implement. 36 | 37 | foo('this should NOT be ' 38 | 'a multi-line string') 39 | 40 | foo("this should NOT be " 41 | 'a multi-line string') 42 | 43 | foo(r"this should NOT be \\t " 44 | r'a multi-line string \\n') 45 | 46 | foo(bR"this should NOT be \\t " 47 | Br'a multi-line string \\n') 48 | 49 | foo("""this should remain as is """ 50 | '''because it is really weird''') 51 | 52 | foo("this should remain as is \\t " 53 | r'because it is really weird \\n') 54 | 55 | foo( 56 | 'this SHOULD be a multi-line string because it is very long and does not fit on one line' 57 | ) 58 | 59 | foo( 60 | 'this SHOULD be re-flowed, but still a multi-line string ' 61 | "because it is very long and does not fit on one line" 62 | ) 63 | 64 | foo( 65 | '''this SHOULD NOT be re-flowed, but still a multi-line string ''' 66 | """because it is very long and does not fit on one line""" 67 | ) 68 | 69 | def foo(): 70 | return ( 71 | "this SHOULD be re-flowed, but still a multi-line string " 72 | "because it is very long and does not fit on one line" 73 | ) 74 | 75 | my_dict["this SHOULD be re-flowed, but still a multi-line string " 76 | "because it is very long and does not fit on one line"] 77 | 78 | 79 | "this SHOULD remain a multi-line string " 80 | "it is very long and does not fit on one line" 81 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 82 | a = 'it is "ok"' 83 | a = "it is 'ok'" 84 | a = "it is 'ok'" 85 | a = 'it is "ok"' 86 | 87 | a = """this is a multiline 88 | string""" 89 | b = """another multiline 90 | string""" 91 | 92 | a = "both 'single' and \\"double\\"" 93 | a = "both 'single' and \\"double\\"" 94 | 95 | a = u"unicode snowman: \\u26C4" 96 | a = r"this does not have a tab: \\t" 97 | a = b"here's some bytes" 98 | 99 | a = """escaped triple quote \\''' in middle""" 100 | a = '''escaped triple quote """ in middle''' 101 | 102 | a = """other triple quote ''' in the middle""" 103 | a = '''other triple quote """ in the middle''' 104 | 105 | a = ( 106 | "this SHOULD be re-flowed, but still a multi-line string " 107 | "because it is very long and does not fit on one line" 108 | ) 109 | 110 | # The interior triple quotes don't get escaped properly 111 | # a = '''both triple quotes """ and \\''' in the middle''' 112 | # a = """both triple quotes ''' and \\""" in the middle""" 113 | 114 | # In the future these might be re-flowed, if that's a feature we want to 115 | # implement. 116 | 117 | foo('this should NOT be ' 118 | 'a multi-line string') 119 | 120 | foo("this should NOT be " 121 | 'a multi-line string') 122 | 123 | foo(r"this should NOT be \\t " 124 | r'a multi-line string \\n') 125 | 126 | foo(bR"this should NOT be \\t " 127 | Br'a multi-line string \\n') 128 | 129 | foo("""this should remain as is """ 130 | '''because it is really weird''') 131 | 132 | foo("this should remain as is \\t " 133 | r'because it is really weird \\n') 134 | 135 | foo("this SHOULD be a multi-line string because it is very long and does not fit on one line") 136 | 137 | foo('this SHOULD be re-flowed, but still a multi-line string ' 138 | "because it is very long and does not fit on one line") 139 | 140 | foo('''this SHOULD NOT be re-flowed, but still a multi-line string ''' 141 | """because it is very long and does not fit on one line""") 142 | 143 | 144 | def foo(): 145 | return ( 146 | "this SHOULD be re-flowed, but still a multi-line string " 147 | "because it is very long and does not fit on one line" 148 | ) 149 | 150 | 151 | my_dict[ 152 | "this SHOULD be re-flowed, but still a multi-line string " 153 | "because it is very long and does not fit on one line" 154 | ] 155 | 156 | 157 | "this SHOULD remain a multi-line string " 158 | "it is very long and does not fit on one line" 159 | 160 | `; 161 | 162 | exports[`strings.py 2`] = ` 163 | a = "it is \\"ok\\"" 164 | a = "it is 'ok'" 165 | a = 'it is \\'ok\\'' 166 | a = 'it is "ok"' 167 | 168 | a = """this is a multiline 169 | string""" 170 | b = '''another multiline 171 | string''' 172 | 173 | a = "both 'single' and \\"double\\"" 174 | a = 'both \\'single\\' and "double"' 175 | 176 | a = u"unicode snowman: \\u26C4" 177 | a = r"this does not have a tab: \\t" 178 | a = b"here's some bytes" 179 | 180 | a = '''escaped triple quote \\''' in middle''' 181 | a = """escaped triple quote \\""" in middle""" 182 | 183 | a = """other triple quote ''' in the middle""" 184 | a = '''other triple quote """ in the middle''' 185 | 186 | a = ("this SHOULD be re-flowed, but still a multi-line string " 187 | "because it is very long and does not fit on one line") 188 | 189 | # The interior triple quotes don't get escaped properly 190 | # a = '''both triple quotes """ and \\''' in the middle''' 191 | # a = """both triple quotes ''' and \\""" in the middle""" 192 | 193 | # In the future these might be re-flowed, if that's a feature we want to 194 | # implement. 195 | 196 | foo('this should NOT be ' 197 | 'a multi-line string') 198 | 199 | foo("this should NOT be " 200 | 'a multi-line string') 201 | 202 | foo(r"this should NOT be \\t " 203 | r'a multi-line string \\n') 204 | 205 | foo(bR"this should NOT be \\t " 206 | Br'a multi-line string \\n') 207 | 208 | foo("""this should remain as is """ 209 | '''because it is really weird''') 210 | 211 | foo("this should remain as is \\t " 212 | r'because it is really weird \\n') 213 | 214 | foo( 215 | 'this SHOULD be a multi-line string because it is very long and does not fit on one line' 216 | ) 217 | 218 | foo( 219 | 'this SHOULD be re-flowed, but still a multi-line string ' 220 | "because it is very long and does not fit on one line" 221 | ) 222 | 223 | foo( 224 | '''this SHOULD NOT be re-flowed, but still a multi-line string ''' 225 | """because it is very long and does not fit on one line""" 226 | ) 227 | 228 | def foo(): 229 | return ( 230 | "this SHOULD be re-flowed, but still a multi-line string " 231 | "because it is very long and does not fit on one line" 232 | ) 233 | 234 | my_dict["this SHOULD be re-flowed, but still a multi-line string " 235 | "because it is very long and does not fit on one line"] 236 | 237 | 238 | "this SHOULD remain a multi-line string " 239 | "it is very long and does not fit on one line" 240 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 241 | a = 'it is "ok"' 242 | a = "it is 'ok'" 243 | a = "it is 'ok'" 244 | a = 'it is "ok"' 245 | 246 | a = """this is a multiline 247 | string""" 248 | b = """another multiline 249 | string""" 250 | 251 | a = "both 'single' and \\"double\\"" 252 | a = "both 'single' and \\"double\\"" 253 | 254 | a = u"unicode snowman: \\u26C4" 255 | a = r"this does not have a tab: \\t" 256 | a = b"here's some bytes" 257 | 258 | a = """escaped triple quote \\''' in middle""" 259 | a = '''escaped triple quote """ in middle''' 260 | 261 | a = """other triple quote ''' in the middle""" 262 | a = '''other triple quote """ in the middle''' 263 | 264 | a = ( 265 | "this SHOULD be re-flowed, but still a multi-line string " 266 | "because it is very long and does not fit on one line" 267 | ) 268 | 269 | # The interior triple quotes don't get escaped properly 270 | # a = '''both triple quotes """ and \\''' in the middle''' 271 | # a = """both triple quotes ''' and \\""" in the middle""" 272 | 273 | # In the future these might be re-flowed, if that's a feature we want to 274 | # implement. 275 | 276 | foo('this should NOT be ' 277 | 'a multi-line string') 278 | 279 | foo("this should NOT be " 280 | 'a multi-line string') 281 | 282 | foo(r"this should NOT be \\t " 283 | r'a multi-line string \\n') 284 | 285 | foo(b'this should NOT be \\\\t a multi-line string \\\\n') 286 | 287 | foo("""this should remain as is """ 288 | '''because it is really weird''') 289 | 290 | foo("this should remain as is \\t " 291 | r'because it is really weird \\n') 292 | 293 | foo("this SHOULD be a multi-line string because it is very long and does not fit on one line") 294 | 295 | foo('this SHOULD be re-flowed, but still a multi-line string ' 296 | "because it is very long and does not fit on one line") 297 | 298 | foo('''this SHOULD NOT be re-flowed, but still a multi-line string ''' 299 | """because it is very long and does not fit on one line""") 300 | 301 | 302 | def foo(): 303 | return ( 304 | "this SHOULD be re-flowed, but still a multi-line string " 305 | "because it is very long and does not fit on one line" 306 | ) 307 | 308 | 309 | my_dict[ 310 | "this SHOULD be re-flowed, but still a multi-line string " 311 | "because it is very long and does not fit on one line" 312 | ] 313 | 314 | 315 | "this SHOULD remain a multi-line string " 316 | "it is very long and does not fit on one line" 317 | 318 | `; 319 | -------------------------------------------------------------------------------- /tests/python_strings/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_strings/strings.py: -------------------------------------------------------------------------------- 1 | a = "it is \"ok\"" 2 | a = "it is 'ok'" 3 | a = 'it is \'ok\'' 4 | a = 'it is "ok"' 5 | 6 | a = """this is a multiline 7 | string""" 8 | b = '''another multiline 9 | string''' 10 | 11 | a = "both 'single' and \"double\"" 12 | a = 'both \'single\' and "double"' 13 | 14 | a = u"unicode snowman: \u26C4" 15 | a = r"this does not have a tab: \t" 16 | a = b"here's some bytes" 17 | 18 | a = '''escaped triple quote \''' in middle''' 19 | a = """escaped triple quote \""" in middle""" 20 | 21 | a = """other triple quote ''' in the middle""" 22 | a = '''other triple quote """ in the middle''' 23 | 24 | a = ("this SHOULD be re-flowed, but still a multi-line string " 25 | "because it is very long and does not fit on one line") 26 | 27 | # The interior triple quotes don't get escaped properly 28 | # a = '''both triple quotes """ and \''' in the middle''' 29 | # a = """both triple quotes ''' and \""" in the middle""" 30 | 31 | # In the future these might be re-flowed, if that's a feature we want to 32 | # implement. 33 | 34 | foo('this should NOT be ' 35 | 'a multi-line string') 36 | 37 | foo("this should NOT be " 38 | 'a multi-line string') 39 | 40 | foo(r"this should NOT be \t " 41 | r'a multi-line string \n') 42 | 43 | foo(bR"this should NOT be \t " 44 | Br'a multi-line string \n') 45 | 46 | foo("""this should remain as is """ 47 | '''because it is really weird''') 48 | 49 | foo("this should remain as is \t " 50 | r'because it is really weird \n') 51 | 52 | foo( 53 | 'this SHOULD be a multi-line string because it is very long and does not fit on one line' 54 | ) 55 | 56 | foo( 57 | 'this SHOULD be re-flowed, but still a multi-line string ' 58 | "because it is very long and does not fit on one line" 59 | ) 60 | 61 | foo( 62 | '''this SHOULD NOT be re-flowed, but still a multi-line string ''' 63 | """because it is very long and does not fit on one line""" 64 | ) 65 | 66 | def foo(): 67 | return ( 68 | "this SHOULD be re-flowed, but still a multi-line string " 69 | "because it is very long and does not fit on one line" 70 | ) 71 | 72 | my_dict["this SHOULD be re-flowed, but still a multi-line string " 73 | "because it is very long and does not fit on one line"] 74 | 75 | 76 | "this SHOULD remain a multi-line string " 77 | "it is very long and does not fit on one line" 78 | -------------------------------------------------------------------------------- /tests/python_subscript/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`subscript.py 1`] = ` 4 | a = [1, [2, 2], 3] 5 | 6 | a[0] 7 | a[0:1] 8 | a[0:-1] 9 | a[-1] 10 | a[0:-1:2] 11 | a[1][0] 12 | a[::-1] 13 | a[1:] 14 | a[:1] 15 | a[:] 16 | 17 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[lower_bound:upper_bound:step] 18 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 19 | long_lower_bound_aaaaaaaaaaa:long_upper_bound_aaaaaaaaaaa:long_step_aaaaaaaaaaa 20 | ] 21 | 22 | c = {'a': 3} 23 | 24 | c['a'] 25 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 | a = [1, [2, 2], 3] 27 | 28 | a[0] 29 | a[0:1] 30 | a[0:-1] 31 | a[-1] 32 | a[0:-1:2] 33 | a[1][0] 34 | a[::-1] 35 | a[1:] 36 | a[:1] 37 | a[:] 38 | 39 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 40 | lower_bound:upper_bound:step 41 | ] 42 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 43 | long_lower_bound_aaaaaaaaaaa: 44 | long_upper_bound_aaaaaaaaaaa: 45 | long_step_aaaaaaaaaaa 46 | ] 47 | 48 | c = {"a": 3} 49 | 50 | c["a"] 51 | 52 | `; 53 | 54 | exports[`subscript.py 2`] = ` 55 | a = [1, [2, 2], 3] 56 | 57 | a[0] 58 | a[0:1] 59 | a[0:-1] 60 | a[-1] 61 | a[0:-1:2] 62 | a[1][0] 63 | a[::-1] 64 | a[1:] 65 | a[:1] 66 | a[:] 67 | 68 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[lower_bound:upper_bound:step] 69 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 70 | long_lower_bound_aaaaaaaaaaa:long_upper_bound_aaaaaaaaaaa:long_step_aaaaaaaaaaa 71 | ] 72 | 73 | c = {'a': 3} 74 | 75 | c['a'] 76 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 77 | a = [1, [2, 2], 3] 78 | 79 | a[0] 80 | a[0:1] 81 | a[0:-1] 82 | a[-1] 83 | a[0:-1:2] 84 | a[1][0] 85 | a[::-1] 86 | a[1:] 87 | a[:1] 88 | a[:] 89 | 90 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 91 | lower_bound:upper_bound:step 92 | ] 93 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 94 | long_lower_bound_aaaaaaaaaaa: 95 | long_upper_bound_aaaaaaaaaaa: 96 | long_step_aaaaaaaaaaa 97 | ] 98 | 99 | c = {"a": 3} 100 | 101 | c["a"] 102 | 103 | `; 104 | -------------------------------------------------------------------------------- /tests/python_subscript/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_subscript/subscript.py: -------------------------------------------------------------------------------- 1 | a = [1, [2, 2], 3] 2 | 3 | a[0] 4 | a[0:1] 5 | a[0:-1] 6 | a[-1] 7 | a[0:-1:2] 8 | a[1][0] 9 | a[::-1] 10 | a[1:] 11 | a[:1] 12 | a[:] 13 | 14 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[lower_bound:upper_bound:step] 15 | long_list_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ 16 | long_lower_bound_aaaaaaaaaaa:long_upper_bound_aaaaaaaaaaa:long_step_aaaaaaaaaaa 17 | ] 18 | 19 | c = {'a': 3} 20 | 21 | c['a'] 22 | -------------------------------------------------------------------------------- /tests/python_tagged_strings/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`tagged_strings.py 1`] = ` 4 | a = r"it is \\ok" 5 | a = u"it is ok" 6 | a = r"""this is a multiline 7 | string""" 8 | a = u"""this is a multiline 9 | string""" 10 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11 | a = r"it is \\ok" 12 | a = u"it is ok" 13 | a = r"""this is a multiline 14 | string""" 15 | a = u"""this is a multiline 16 | string""" 17 | 18 | `; 19 | 20 | exports[`tagged_strings.py 2`] = ` 21 | a = r"it is \\ok" 22 | a = u"it is ok" 23 | a = r"""this is a multiline 24 | string""" 25 | a = u"""this is a multiline 26 | string""" 27 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 | a = r"it is \\ok" 29 | a = u"it is ok" 30 | a = r"""this is a multiline 31 | string""" 32 | a = u"""this is a multiline 33 | string""" 34 | 35 | `; 36 | -------------------------------------------------------------------------------- /tests/python_tagged_strings/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_tagged_strings/tagged_strings.py: -------------------------------------------------------------------------------- 1 | a = r"it is \ok" 2 | a = u"it is ok" 3 | a = r"""this is a multiline 4 | string""" 5 | a = u"""this is a multiline 6 | string""" 7 | -------------------------------------------------------------------------------- /tests/python_try/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`try.py 1`] = ` 4 | try: 5 | f = open('myfile.txt') 6 | s = f.readline() 7 | i = int(s.strip()) 8 | except OSError as err: 9 | print("OS error: {0}".format(err)) 10 | except ValueError: 11 | print("Could not convert data to an integer.") 12 | raise ValueError 13 | except: 14 | print("Unexpected error:") 15 | raise 16 | finally: 17 | print("done") 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | try: 20 | f = open("myfile.txt") 21 | s = f.readline() 22 | i = int(s.strip()) 23 | except OSError as err: 24 | print("OS error: {0}".format(err)) 25 | except ValueError: 26 | print("Could not convert data to an integer.") 27 | raise ValueError 28 | except: 29 | print("Unexpected error:") 30 | raise 31 | finally: 32 | print("done") 33 | 34 | `; 35 | 36 | exports[`try.py 2`] = ` 37 | try: 38 | f = open('myfile.txt') 39 | s = f.readline() 40 | i = int(s.strip()) 41 | except OSError as err: 42 | print("OS error: {0}".format(err)) 43 | except ValueError: 44 | print("Could not convert data to an integer.") 45 | raise ValueError 46 | except: 47 | print("Unexpected error:") 48 | raise 49 | finally: 50 | print("done") 51 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 | try: 53 | f = open("myfile.txt") 54 | s = f.readline() 55 | i = int(s.strip()) 56 | except OSError as err: 57 | print("OS error: {0}".format(err)) 58 | except ValueError: 59 | print("Could not convert data to an integer.") 60 | raise ValueError 61 | except: 62 | print("Unexpected error:") 63 | raise 64 | finally: 65 | print("done") 66 | 67 | `; 68 | -------------------------------------------------------------------------------- /tests/python_try/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_try/try.py: -------------------------------------------------------------------------------- 1 | try: 2 | f = open('myfile.txt') 3 | s = f.readline() 4 | i = int(s.strip()) 5 | except OSError as err: 6 | print("OS error: {0}".format(err)) 7 | except ValueError: 8 | print("Could not convert data to an integer.") 9 | raise ValueError 10 | except: 11 | print("Unexpected error:") 12 | raise 13 | finally: 14 | print("done") 15 | -------------------------------------------------------------------------------- /tests/python_tuple/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`tuple.py 1`] = ` 4 | () 5 | 1, 6 | (1,) 7 | (1, 2) 8 | (1, 2, 3,) 9 | 10 | foo(()) 11 | foo((1,)) 12 | foo((1, 2)) 13 | foo((1, 2,)) 14 | 15 | x[()] 16 | x[(1,)] 17 | x[1,] 18 | x[(1, 2)] 19 | x[(1, 2,)] 20 | 21 | ((), ()) 22 | ((), (1,)) 23 | ((), (1, 2)) 24 | 25 | [(), (1), (1,), (1, 2), (1, 2,)] 26 | 27 | (very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 28 | 29 | a, b = very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 30 | 31 | a = (1, 32 | 2, 33 | 3) 34 | 35 | 36 | def f(): 37 | return (1, 2) 38 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 39 | () 40 | (1,) 41 | (1,) 42 | (1, 2) 43 | (1, 2, 3) 44 | 45 | foo(()) 46 | foo((1,)) 47 | foo((1, 2)) 48 | foo((1, 2)) 49 | 50 | x[()] 51 | x[1,] 52 | x[1,] 53 | x[1, 2] 54 | x[1, 2] 55 | 56 | ((), ()) 57 | ((), (1,)) 58 | ((), (1, 2)) 59 | 60 | [(), 1, (1,), (1, 2), (1, 2)] 61 | 62 | ( 63 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 64 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 65 | ) 66 | 67 | a, b = ( 68 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 69 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 70 | ) 71 | 72 | a = (1, 2, 3) 73 | 74 | 75 | def f(): 76 | return 1, 2 77 | 78 | `; 79 | 80 | exports[`tuple.py 2`] = ` 81 | () 82 | 1, 83 | (1,) 84 | (1, 2) 85 | (1, 2, 3,) 86 | 87 | foo(()) 88 | foo((1,)) 89 | foo((1, 2)) 90 | foo((1, 2,)) 91 | 92 | x[()] 93 | x[(1,)] 94 | x[1,] 95 | x[(1, 2)] 96 | x[(1, 2,)] 97 | 98 | ((), ()) 99 | ((), (1,)) 100 | ((), (1, 2)) 101 | 102 | [(), (1), (1,), (1, 2), (1, 2,)] 103 | 104 | (very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 105 | 106 | a, b = very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 107 | 108 | a = (1, 109 | 2, 110 | 3) 111 | 112 | 113 | def f(): 114 | return (1, 2) 115 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 116 | () 117 | (1,) 118 | (1,) 119 | (1, 2) 120 | (1, 2, 3) 121 | 122 | foo(()) 123 | foo((1,)) 124 | foo((1, 2)) 125 | foo((1, 2)) 126 | 127 | x[()] 128 | x[1,] 129 | x[1,] 130 | x[1, 2] 131 | x[1, 2] 132 | 133 | ((), ()) 134 | ((), (1,)) 135 | ((), (1, 2)) 136 | 137 | [(), 1, (1,), (1, 2), (1, 2)] 138 | 139 | ( 140 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 141 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 142 | ) 143 | 144 | a, b = ( 145 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 146 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 147 | ) 148 | 149 | a = (1, 2, 3) 150 | 151 | 152 | def f(): 153 | return 1, 2 154 | 155 | `; 156 | 157 | exports[`tuple.py 3`] = ` 158 | () 159 | 1, 160 | (1,) 161 | (1, 2) 162 | (1, 2, 3,) 163 | 164 | foo(()) 165 | foo((1,)) 166 | foo((1, 2)) 167 | foo((1, 2,)) 168 | 169 | x[()] 170 | x[(1,)] 171 | x[1,] 172 | x[(1, 2)] 173 | x[(1, 2,)] 174 | 175 | ((), ()) 176 | ((), (1,)) 177 | ((), (1, 2)) 178 | 179 | [(), (1), (1,), (1, 2), (1, 2,)] 180 | 181 | (very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 182 | 183 | a, b = very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 184 | 185 | a = (1, 186 | 2, 187 | 3) 188 | 189 | 190 | def f(): 191 | return (1, 2) 192 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 193 | () 194 | (1,) 195 | (1,) 196 | (1, 2) 197 | (1, 2, 3) 198 | 199 | foo(()) 200 | foo((1,)) 201 | foo((1, 2)) 202 | foo((1, 2)) 203 | 204 | x[()] 205 | x[1,] 206 | x[1,] 207 | x[1, 2] 208 | x[1, 2] 209 | 210 | ((), ()) 211 | ((), (1,)) 212 | ((), (1, 2)) 213 | 214 | [(), 1, (1,), (1, 2), (1, 2)] 215 | 216 | ( 217 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 218 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 219 | ) 220 | 221 | a, b = ( 222 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 223 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 224 | ) 225 | 226 | a = (1, 2, 3) 227 | 228 | 229 | def f(): 230 | return 1, 2 231 | 232 | `; 233 | -------------------------------------------------------------------------------- /tests/python_tuple/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" }); 3 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 4 | -------------------------------------------------------------------------------- /tests/python_tuple/tuple.py: -------------------------------------------------------------------------------- 1 | () 2 | 1, 3 | (1,) 4 | (1, 2) 5 | (1, 2, 3,) 6 | 7 | foo(()) 8 | foo((1,)) 9 | foo((1, 2)) 10 | foo((1, 2,)) 11 | 12 | x[()] 13 | x[(1,)] 14 | x[1,] 15 | x[(1, 2)] 16 | x[(1, 2,)] 17 | 18 | ((), ()) 19 | ((), (1,)) 20 | ((), (1, 2)) 21 | 22 | [(), (1), (1,), (1, 2), (1, 2,)] 23 | 24 | (very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) 25 | 26 | a, b = very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 27 | 28 | a = (1, 29 | 2, 30 | 3) 31 | 32 | 33 | def f(): 34 | return (1, 2) 35 | -------------------------------------------------------------------------------- /tests/python_uadd/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`uadd.py 1`] = ` 4 | +a 5 | +1 6 | -a 7 | -1 8 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | +a 10 | +1 11 | -a 12 | -1 13 | 14 | `; 15 | -------------------------------------------------------------------------------- /tests/python_uadd/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python_uadd/uadd.py: -------------------------------------------------------------------------------- 1 | +a 2 | +1 3 | -a 4 | -1 5 | -------------------------------------------------------------------------------- /tests/python_while/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`while.py 1`] = ` 4 | while True: 5 | print(10) 6 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 | while True: 8 | print(10) 9 | 10 | `; 11 | 12 | exports[`while.py 2`] = ` 13 | while True: 14 | print(10) 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | while True: 17 | print(10) 18 | 19 | `; 20 | -------------------------------------------------------------------------------- /tests/python_while/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_while/while.py: -------------------------------------------------------------------------------- 1 | while True: 2 | print(10) 3 | -------------------------------------------------------------------------------- /tests/python_with/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`with.py 1`] = ` 4 | with open('tmp/index.html') as f: 5 | index = f.read() 6 | 7 | with open('tmp/index.html'): 8 | print('great') 9 | 10 | with A() as X, B() as Y, C() as Z: 11 | do_something() 12 | 13 | with A() as X: 14 | with B() as Y: 15 | with C() as Z: 16 | do_something() 17 | 18 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: pass 19 | 20 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: long_function_name() 21 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22 | with open("tmp/index.html") as f: 23 | index = f.read() 24 | 25 | with open("tmp/index.html"): 26 | print("great") 27 | 28 | with A() as X, B() as Y, C() as Z: 29 | do_something() 30 | 31 | with A() as X: 32 | with B() as Y: 33 | with C() as Z: 34 | do_something() 35 | 36 | with \\ 37 | long_context_manager_1_aaaaaa, \\ 38 | long_context_manager_1_aaaaaa, \\ 39 | long_context_manager_1_aaaaaa: 40 | pass 41 | 42 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: 43 | long_function_name() 44 | 45 | `; 46 | 47 | exports[`with.py 2`] = ` 48 | with open('tmp/index.html') as f: 49 | index = f.read() 50 | 51 | with open('tmp/index.html'): 52 | print('great') 53 | 54 | with A() as X, B() as Y, C() as Z: 55 | do_something() 56 | 57 | with A() as X: 58 | with B() as Y: 59 | with C() as Z: 60 | do_something() 61 | 62 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: pass 63 | 64 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: long_function_name() 65 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66 | with open("tmp/index.html") as f: 67 | index = f.read() 68 | 69 | with open("tmp/index.html"): 70 | print("great") 71 | 72 | with A() as X, B() as Y, C() as Z: 73 | do_something() 74 | 75 | with A() as X: 76 | with B() as Y: 77 | with C() as Z: 78 | do_something() 79 | 80 | with \\ 81 | long_context_manager_1_aaaaaa, \\ 82 | long_context_manager_1_aaaaaa, \\ 83 | long_context_manager_1_aaaaaa: 84 | pass 85 | 86 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: 87 | long_function_name() 88 | 89 | `; 90 | -------------------------------------------------------------------------------- /tests/python_with/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_with/with.py: -------------------------------------------------------------------------------- 1 | with open('tmp/index.html') as f: 2 | index = f.read() 3 | 4 | with open('tmp/index.html'): 5 | print('great') 6 | 7 | with A() as X, B() as Y, C() as Z: 8 | do_something() 9 | 10 | with A() as X: 11 | with B() as Y: 12 | with C() as Z: 13 | do_something() 14 | 15 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: pass 16 | 17 | with long_context_manager_1_aaaaaa, long_context_manager_1_aaaaaa: long_function_name() 18 | -------------------------------------------------------------------------------- /tests/python_yield/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`yield.py 1`] = ` 4 | def example(first): 5 | if False: 6 | yield 7 | 8 | yield first 9 | 10 | 11 | def should_wrap(): 12 | yield very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 13 | 14 | 15 | def should_unwrap(): 16 | yield \\ 17 | short_variable_name 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | def example(first): 20 | if False: 21 | yield 22 | 23 | yield first 24 | 25 | 26 | def should_wrap(): 27 | yield \\ 28 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 29 | 30 | 31 | def should_unwrap(): 32 | yield short_variable_name 33 | 34 | `; 35 | 36 | exports[`yield.py 2`] = ` 37 | def example(first): 38 | if False: 39 | yield 40 | 41 | yield first 42 | 43 | 44 | def should_wrap(): 45 | yield very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 46 | 47 | 48 | def should_unwrap(): 49 | yield \\ 50 | short_variable_name 51 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 | def example(first): 53 | if False: 54 | yield 55 | 56 | yield first 57 | 58 | 59 | def should_wrap(): 60 | yield \\ 61 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 62 | 63 | 64 | def should_unwrap(): 65 | yield short_variable_name 66 | 67 | `; 68 | -------------------------------------------------------------------------------- /tests/python_yield/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "2" }); 2 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 3 | -------------------------------------------------------------------------------- /tests/python_yield/yield.py: -------------------------------------------------------------------------------- 1 | def example(first): 2 | if False: 3 | yield 4 | 5 | yield first 6 | 7 | 8 | def should_wrap(): 9 | yield very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 10 | 11 | 12 | def should_unwrap(): 13 | yield \ 14 | short_variable_name 15 | -------------------------------------------------------------------------------- /tests/python_yield_from/__snapshots__/jsfmt.spec.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`yield_from.py 1`] = ` 4 | def example(first): 5 | yield from first 6 | 7 | 8 | def should_wrap(): 9 | yield from very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 10 | 11 | 12 | def should_unwrap(): 13 | yield from \\ 14 | short_variable_name 15 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16 | def example(first): 17 | yield from first 18 | 19 | 20 | def should_wrap(): 21 | yield from \\ 22 | very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 23 | 24 | 25 | def should_unwrap(): 26 | yield from short_variable_name 27 | 28 | `; 29 | -------------------------------------------------------------------------------- /tests/python_yield_from/jsfmt.spec.js: -------------------------------------------------------------------------------- 1 | run_spec(__dirname, ["python"], { pythonVersion: "3" }); 2 | -------------------------------------------------------------------------------- /tests/python_yield_from/yield_from.py: -------------------------------------------------------------------------------- 1 | def example(first): 2 | yield from first 3 | 4 | 5 | def should_wrap(): 6 | yield from very_long_variable_name_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 7 | 8 | 9 | def should_unwrap(): 10 | yield from \ 11 | short_variable_name 12 | -------------------------------------------------------------------------------- /tests_config/pycodestyle.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const spawnSync = require("child_process").spawnSync; 4 | const path = require("path"); 5 | const normalizeOptions = require("prettier/src/main/options").normalize; 6 | 7 | // Only enable subset of errors that prettier should handle and use the 8 | // default ignored error list. 9 | // See http://pycodestyle.pycqa.org/en/latest/intro.html#error-codes 10 | const selectedErrors = ["E1", "E2", "E3", "W1", "W2", "W3", "W5"]; 11 | const ignoredErrors = [ 12 | "E121", 13 | "E123", 14 | "E126", 15 | "E133", 16 | "E226", 17 | "E241", 18 | "E242", 19 | "E704", 20 | "W503", 21 | "W504" 22 | ]; 23 | 24 | function getPycodestyleOutput(string, options) { 25 | const normalizedOptions = normalizeOptions(options); 26 | 27 | // Use the same version of Python to run pycodestyle that we're using for 28 | // prettier. 29 | const pythonExectuable = `python${ 30 | normalizedOptions.pythonVersion == "2" ? "" : "3" 31 | }`; 32 | 33 | const executionResult = spawnSync( 34 | pythonExectuable, 35 | [ 36 | path.join(__dirname, "../vendor/python/pycodestyle.py"), 37 | `--select=${selectedErrors.join(",")}`, 38 | `--ignore=${ignoredErrors.join(",")}`, 39 | `--max-line-length=${normalizedOptions.printWidth}`, 40 | "-" 41 | ], 42 | { 43 | input: string 44 | } 45 | ); 46 | 47 | if (!executionResult.stderr) { 48 | throw new Error("Failed to execute pycodestyle"); 49 | } 50 | 51 | const error = executionResult.stderr.toString(); 52 | 53 | if (error) { 54 | throw new Error(error); 55 | } 56 | 57 | return executionResult.stdout.toString(); 58 | } 59 | 60 | module.exports = { 61 | getPycodestyleOutput: getPycodestyleOutput 62 | }; 63 | -------------------------------------------------------------------------------- /tests_config/raw-serializer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const RAW = Symbol.for("raw"); 4 | 5 | module.exports = { 6 | print(val) { 7 | return val[RAW]; 8 | }, 9 | test(val) { 10 | return ( 11 | val && 12 | Object.prototype.hasOwnProperty.call(val, RAW) && 13 | typeof val[RAW] === "string" 14 | ); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /tests_config/run_spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const fs = require("fs"); 4 | const extname = require("path").extname; 5 | const prettier = require("prettier"); 6 | const massageAST = require("prettier/src/common/clean-ast").massageAST; 7 | const normalizeOptions = require("prettier/src/main/options").normalize; 8 | const getPycodestyleOutput = require("./pycodestyle").getPycodestyleOutput; 9 | 10 | const AST_COMPARE = process.env["AST_COMPARE"]; 11 | const PEP8_VALIDATE = process.env["PEP8_VALIDATE"]; 12 | 13 | function run_spec(dirname, parsers, options) { 14 | options = Object.assign( 15 | { 16 | plugins: ["."] 17 | }, 18 | options 19 | ); 20 | 21 | /* instabul ignore if */ 22 | if (!parsers || !parsers.length) { 23 | throw new Error(`No parsers were specified for ${dirname}`); 24 | } 25 | 26 | fs.readdirSync(dirname).forEach(filename => { 27 | const path = dirname + "/" + filename; 28 | if ( 29 | extname(filename) !== ".snap" && 30 | fs.lstatSync(path).isFile() && 31 | filename[0] !== "." && 32 | filename !== "jsfmt.spec.js" 33 | ) { 34 | const source = read(path).replace(/\r\n/g, "\n"); 35 | 36 | const mergedOptions = Object.assign({}, options, { 37 | parser: parsers[0] 38 | }); 39 | const output = prettyprint(source, path, mergedOptions); 40 | test(`${filename} - ${mergedOptions.parser}-verify`, () => { 41 | expect(raw(source + "~".repeat(80) + "\n" + output)).toMatchSnapshot( 42 | filename 43 | ); 44 | 45 | if (PEP8_VALIDATE) { 46 | expect(getPycodestyleOutput(output, mergedOptions)).toEqual(""); 47 | } 48 | }); 49 | 50 | parsers.slice(1).forEach(parserName => { 51 | test(`${filename} - ${parserName}-verify`, () => { 52 | const verifyOptions = Object.assign(mergedOptions, { 53 | parser: parserName 54 | }); 55 | const verifyOutput = prettyprint(source, path, verifyOptions); 56 | expect(output).toEqual(verifyOutput); 57 | }); 58 | }); 59 | 60 | if (AST_COMPARE) { 61 | const ast = parse(source, mergedOptions); 62 | const normalizedOptions = normalizeOptions(mergedOptions); 63 | const astMassaged = massageAST(ast, normalizedOptions); 64 | let ppastMassaged; 65 | let pperr = null; 66 | try { 67 | const ppast = parse( 68 | prettyprint(source, path, mergedOptions), 69 | mergedOptions 70 | ); 71 | ppastMassaged = massageAST(ppast, normalizedOptions); 72 | } catch (e) { 73 | pperr = e.stack; 74 | } 75 | 76 | test(path + " parse", () => { 77 | expect(pperr).toBe(null); 78 | expect(ppastMassaged).toBeDefined(); 79 | if (!ast.errors || ast.errors.length === 0) { 80 | expect(astMassaged).toEqual(ppastMassaged); 81 | } 82 | }); 83 | } 84 | } 85 | }); 86 | } 87 | global.run_spec = run_spec; 88 | 89 | /** 90 | * This gets rid of extra keys not removed by the massageAST function which are not suitable or relevant when 91 | * comparing two different ASTs. 92 | */ 93 | function stripExtraNonComparableKeys(ast) { 94 | if (Array.isArray(ast)) { 95 | return ast.map(e => stripExtraNonComparableKeys(e)); 96 | } 97 | if (typeof ast === "object") { 98 | const newObj = {}; 99 | for (const key in ast) { 100 | if (key === "text") { 101 | continue; 102 | } 103 | newObj[key] = stripExtraNonComparableKeys(ast[key]); 104 | } 105 | return newObj; 106 | } 107 | return ast; 108 | } 109 | 110 | function parse(string, opts) { 111 | return stripExtraNonComparableKeys(prettier.__debug.parse(string, opts)); 112 | } 113 | 114 | function prettyprint(src, filename, options) { 115 | return prettier.format( 116 | src, 117 | Object.assign( 118 | { 119 | filepath: filename 120 | }, 121 | options 122 | ) 123 | ); 124 | } 125 | 126 | function read(filename) { 127 | return fs.readFileSync(filename, "utf8"); 128 | } 129 | 130 | /** 131 | * Wraps a string in a marker object that is used by `./raw-serializer.js` to 132 | * directly print that string in a snapshot without escaping all double quotes. 133 | * Backticks will still be escaped. 134 | */ 135 | function raw(string) { 136 | if (typeof string !== "string") { 137 | throw new Error("Raw snapshots have to be strings."); 138 | } 139 | return { [Symbol.for("raw")]: string }; 140 | } 141 | -------------------------------------------------------------------------------- /vendor/python/astexport.py: -------------------------------------------------------------------------------- 1 | """ 2 | astexport.py - See https://github.com/fpoli/python-astexport 3 | 4 | Copyright (c) 2015, Federico Poli 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | """ 24 | 25 | import ast 26 | import fileinput 27 | import json 28 | import tokenize 29 | 30 | import asttokens 31 | 32 | 33 | def export_json(atok, pretty_print=False): 34 | dict = export_dict(atok) 35 | 36 | dict['comments'] = [{ 37 | 'ast_type': 'comment', 38 | 'value': token.string, 39 | 'start': token.startpos, 40 | 'end': token.endpos, 41 | 'loc': { 42 | 'start': { 43 | 'line': token.start[0], 44 | 'column': token.start[1] 45 | }, 46 | 'end': { 47 | 'line': token.end[0], 48 | 'column': token.end[1] 49 | } 50 | } 51 | } for token in atok.tokens if token.type == tokenize.COMMENT] 52 | 53 | return json.dumps( 54 | dict, 55 | indent=4 if pretty_print else None, 56 | sort_keys=True, 57 | separators=(",", ": ") if pretty_print else (",", ":") 58 | ) 59 | 60 | 61 | def export_dict(atok): 62 | return DictExportVisitor(atok).visit(atok.tree) 63 | 64 | 65 | class DictExportVisitor: 66 | ast_type_field = "ast_type" 67 | 68 | def __init__(self, atok): 69 | self.atok = atok 70 | 71 | def visit(self, node): 72 | node_type = node.__class__.__name__ 73 | meth = getattr(self, "visit_" + node_type, self.default_visit) 74 | return meth(node) 75 | 76 | def default_visit(self, node): 77 | node_type = node.__class__.__name__ 78 | # Add node type 79 | args = { 80 | self.ast_type_field: node_type 81 | } 82 | # Visit fields 83 | for field in node._fields: 84 | assert field != self.ast_type_field 85 | meth = getattr( 86 | self, "visit_field_" + node_type + "_" + field, 87 | self.default_visit_field 88 | ) 89 | args[field] = meth(getattr(node, field)) 90 | # Visit attributes 91 | for attr in node._attributes: 92 | assert attr != self.ast_type_field 93 | meth = getattr( 94 | self, "visit_attribute_" + node_type + "_" + attr, 95 | self.default_visit_field 96 | ) 97 | # Use None as default when lineno/col_offset are not set 98 | args[attr] = meth(getattr(node, attr, None)) 99 | 100 | if hasattr(node, 'first_token'): 101 | args['start'] = node.first_token.startpos 102 | args['end'] = node.last_token.endpos 103 | 104 | args['source'] = self.atok.get_text(node) 105 | 106 | return args 107 | 108 | def default_visit_field(self, val): 109 | if isinstance(val, ast.AST): 110 | return self.visit(val) 111 | elif isinstance(val, list) or isinstance(val, tuple): 112 | return [self.visit(x) for x in val] 113 | else: 114 | return val 115 | 116 | # Special visitors 117 | def visit_NoneType(self, val): 118 | return None 119 | 120 | def visit_str(self, val): 121 | return val 122 | 123 | def visit_field_NameConstant_value(self, val): 124 | return str(val) 125 | 126 | def visit_Bytes(self, val): 127 | return str(val.s) 128 | 129 | def visit_field_Num_n(self, val): 130 | if isinstance(val, int): 131 | return { 132 | self.ast_type_field: "int", 133 | "n": str(val) 134 | } 135 | elif isinstance(val, float): 136 | return { 137 | self.ast_type_field: "float", 138 | "n": str(val) 139 | } 140 | elif isinstance(val, complex): 141 | return { 142 | self.ast_type_field: "complex", 143 | "n": str(val.real), 144 | "i": str(val.imag) 145 | } 146 | 147 | 148 | def parse(source): 149 | assert (isinstance(source, str)) 150 | 151 | atok = asttokens.ASTTokens(source, parse=True) 152 | 153 | return atok 154 | 155 | 156 | def main(): 157 | source = "".join(fileinput.input()) 158 | 159 | tree = parse(source) 160 | json = export_json(tree, True) 161 | print(json) 162 | 163 | 164 | if __name__ == '__main__': 165 | main() 166 | -------------------------------------------------------------------------------- /vendor/python/asttokens/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Grist Labs, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """ 16 | This module enhances the Python AST tree with token and source code information, sufficent to 17 | detect the source text of each AST node. This is helpful for tools that make source code 18 | transformations. 19 | """ 20 | 21 | from .line_numbers import LineNumbers 22 | from .asttokens import ASTTokens 23 | -------------------------------------------------------------------------------- /vendor/python/asttokens/asttokens.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Grist Labs, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import ast 16 | import bisect 17 | import token 18 | import tokenize 19 | import io 20 | import six 21 | from six.moves import xrange # pylint: disable=redefined-builtin 22 | from .line_numbers import LineNumbers 23 | from .util import Token, match_token 24 | from .mark_tokens import MarkTokens 25 | 26 | class ASTTokens(object): 27 | """ 28 | ASTTokens maintains the text of Python code in several forms: as a string, as line numbers, and 29 | as tokens, and is used to mark and access token and position information. 30 | 31 | ``source_text`` must be a unicode or UTF8-encoded string. If you pass in UTF8 bytes, remember 32 | that all offsets you'll get are to the unicode text, which is available as the ``.text`` 33 | property. 34 | 35 | If ``parse`` is set, the ``source_text`` will be parsed with ``ast.parse()``, and the resulting 36 | tree marked with token info and made available as the ``.tree`` property. 37 | 38 | If ``tree`` is given, it will be marked and made available as the ``.tree`` property. In 39 | addition to the trees produced by the ``ast`` module, ASTTokens will also mark trees produced 40 | using ``astroid`` library . 41 | 42 | If only ``source_text`` is given, you may use ``.mark_tokens(tree)`` to mark the nodes of an AST 43 | tree created separately. 44 | """ 45 | def __init__(self, source_text, parse=False, tree=None, filename=''): 46 | if isinstance(source_text, six.binary_type): 47 | source_text = source_text.decode('utf8') 48 | 49 | self._filename = filename 50 | self._tree = ast.parse(source_text, filename) if parse else tree 51 | 52 | self._text = source_text 53 | self._line_numbers = LineNumbers(source_text) 54 | 55 | # Tokenize the code. 56 | self._tokens = list(self._generate_tokens(source_text)) 57 | 58 | # Extract the start positions of all tokens, so that we can quickly map positions to tokens. 59 | self._token_offsets = [tok.startpos for tok in self._tokens] 60 | 61 | if self._tree: 62 | self.mark_tokens(self._tree) 63 | 64 | 65 | def mark_tokens(self, root_node): 66 | """ 67 | Given the root of the AST or Astroid tree produced from source_text, visits all nodes marking 68 | them with token and position information by adding ``.first_token`` and 69 | ``.last_token``attributes. This is done automatically in the constructor when ``parse`` or 70 | ``tree`` arguments are set, but may be used manually with a separate AST or Astroid tree. 71 | """ 72 | # The hard work of this class is done by MarkTokens 73 | MarkTokens(self).visit_tree(root_node) 74 | 75 | 76 | def _generate_tokens(self, text): 77 | """ 78 | Generates tokens for the given code. 79 | """ 80 | # This is technically an undocumented API for Python3, but allows us to use the same API as for 81 | # Python2. See http://stackoverflow.com/a/4952291/328565. 82 | for index, tok in enumerate(tokenize.generate_tokens(io.StringIO(text).readline)): 83 | tok_type, tok_str, start, end, line = tok 84 | yield Token(tok_type, tok_str, start, end, line, index, 85 | self._line_numbers.line_to_offset(start[0], start[1]), 86 | self._line_numbers.line_to_offset(end[0], end[1])) 87 | 88 | @property 89 | def text(self): 90 | """The source code passed into the constructor.""" 91 | return self._text 92 | 93 | @property 94 | def tokens(self): 95 | """The list of tokens corresponding to the source code from the constructor.""" 96 | return self._tokens 97 | 98 | @property 99 | def tree(self): 100 | """The root of the AST tree passed into the constructor or parsed from the source code.""" 101 | return self._tree 102 | 103 | @property 104 | def filename(self): 105 | """The filename that was parsed""" 106 | return self._filename 107 | 108 | def get_token_from_offset(self, offset): 109 | """ 110 | Returns the token containing the given character offset (0-based position in source text), 111 | or the preceeding token if the position is between tokens. 112 | """ 113 | return self._tokens[bisect.bisect(self._token_offsets, offset) - 1] 114 | 115 | def get_token(self, lineno, col_offset): 116 | """ 117 | Returns the token containing the given (lineno, col_offset) position, or the preceeding token 118 | if the position is between tokens. 119 | """ 120 | # TODO: add test for multibyte unicode. We need to translate offsets from ast module (which 121 | # are in utf8) to offsets into the unicode text. tokenize module seems to use unicode offsets 122 | # but isn't explicit. 123 | return self.get_token_from_offset(self._line_numbers.line_to_offset(lineno, col_offset)) 124 | 125 | def get_token_from_utf8(self, lineno, col_offset): 126 | """ 127 | Same as get_token(), but interprets col_offset as a UTF8 offset, which is what `ast` uses. 128 | """ 129 | return self.get_token(lineno, self._line_numbers.from_utf8_col(lineno, col_offset)) 130 | 131 | def next_token(self, tok, include_extra=False): 132 | """ 133 | Returns the next token after the given one. If include_extra is True, includes non-coding 134 | tokens from the tokenize module, such as NL and COMMENT. 135 | """ 136 | i = tok.index + 1 137 | if not include_extra: 138 | while self._tokens[i].type >= token.N_TOKENS: 139 | i += 1 140 | return self._tokens[i] 141 | 142 | def prev_token(self, tok, include_extra=False): 143 | """ 144 | Returns the previous token before the given one. If include_extra is True, includes non-coding 145 | tokens from the tokenize module, such as NL and COMMENT. 146 | """ 147 | i = tok.index - 1 148 | if not include_extra: 149 | while self._tokens[i].type >= token.N_TOKENS: 150 | i -= 1 151 | return self._tokens[i] 152 | 153 | def find_token(self, start_token, tok_type, tok_str=None, reverse=False): 154 | """ 155 | Looks for the first token, starting at start_token, that matches tok_type and, if given, the 156 | token string. Searches backwards if reverse is True. Returns ENDMARKER token if not found (you 157 | can check it with `token.ISEOF(t.type)`. 158 | """ 159 | t = start_token 160 | advance = self.prev_token if reverse else self.next_token 161 | while not match_token(t, tok_type, tok_str) and not token.ISEOF(t.type): 162 | t = advance(t, include_extra=True) 163 | return t 164 | 165 | def token_range(self, first_token, last_token, include_extra=False): 166 | """ 167 | Yields all tokens in order from first_token through and including last_token. If 168 | include_extra is True, includes non-coding tokens such as tokenize.NL and .COMMENT. 169 | """ 170 | for i in xrange(first_token.index, last_token.index + 1): 171 | if include_extra or self._tokens[i].type < token.N_TOKENS: 172 | yield self._tokens[i] 173 | 174 | def get_tokens(self, node, include_extra=False): 175 | """ 176 | Yields all tokens making up the given node. If include_extra is True, includes non-coding 177 | tokens such as tokenize.NL and .COMMENT. 178 | """ 179 | return self.token_range(node.first_token, node.last_token, include_extra=include_extra) 180 | 181 | def get_text_range(self, node): 182 | """ 183 | After mark_tokens() has been called, returns the (startpos, endpos) positions in source text 184 | corresponding to the given node. Returns (0, 0) for nodes (like `Load`) that don't correspond 185 | to any particular text. 186 | """ 187 | if not hasattr(node, 'first_token'): 188 | return (0, 0) 189 | 190 | start = node.first_token.startpos 191 | if any(match_token(t, token.NEWLINE) for t in self.get_tokens(node)): 192 | # Multi-line nodes would be invalid unless we keep the indentation of the first node. 193 | start = self._text.rfind('\n', 0, start) + 1 194 | 195 | return (start, node.last_token.endpos) 196 | 197 | def get_text(self, node): 198 | """ 199 | After mark_tokens() has been called, returns the text corresponding to the given node. Returns 200 | '' for nodes (like `Load`) that don't correspond to any particular text. 201 | """ 202 | start, end = self.get_text_range(node) 203 | return self._text[start : end] 204 | -------------------------------------------------------------------------------- /vendor/python/asttokens/line_numbers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Grist Labs, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import bisect 16 | import re 17 | 18 | _line_start_re = re.compile(r'^', re.M) 19 | 20 | class LineNumbers(object): 21 | """ 22 | Class to convert between character offsets in a text string, and pairs (line, column) of 1-based 23 | line and 0-based column numbers, as used by tokens and AST nodes. 24 | 25 | This class expects unicode for input and stores positions in unicode. But it supports 26 | translating to and from utf8 offsets, which are used by ast parsing. 27 | """ 28 | def __init__(self, text): 29 | # A list of character offsets of each line's first character. 30 | self._line_offsets = [m.start(0) for m in _line_start_re.finditer(text)] 31 | self._text = text 32 | self._text_len = len(text) 33 | self._utf8_offset_cache = {} # maps line num to list of char offset for each byte in line 34 | 35 | def from_utf8_col(self, line, utf8_column): 36 | """ 37 | Given a 1-based line number and 0-based utf8 column, returns a 0-based unicode column. 38 | """ 39 | offsets = self._utf8_offset_cache.get(line) 40 | if offsets is None: 41 | end_offset = self._line_offsets[line] if line < len(self._line_offsets) else self._text_len 42 | line_text = self._text[self._line_offsets[line - 1] : end_offset] 43 | 44 | offsets = [i for i,c in enumerate(line_text) for byte in c.encode('utf8')] 45 | offsets.append(len(line_text)) 46 | self._utf8_offset_cache[line] = offsets 47 | 48 | return offsets[max(0, min(len(offsets), utf8_column))] 49 | 50 | def line_to_offset(self, line, column): 51 | """ 52 | Converts 1-based line number and 0-based column to 0-based character offset into text. 53 | """ 54 | line -= 1 55 | if line >= len(self._line_offsets): 56 | return self._text_len 57 | elif line < 0: 58 | return 0 59 | else: 60 | return min(self._line_offsets[line] + max(0, column), self._text_len) 61 | 62 | def offset_to_line(self, offset): 63 | """ 64 | Converts 0-based character offset to pair (line, col) of 1-based line and 0-based column 65 | numbers. 66 | """ 67 | offset = max(0, min(self._text_len, offset)) 68 | line_index = bisect.bisect_right(self._line_offsets, offset) - 1 69 | return (line_index + 1, offset - self._line_offsets[line_index]) 70 | 71 | 72 | -------------------------------------------------------------------------------- /vendor/python/asttokens/util.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Grist Labs, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import ast 16 | import collections 17 | import token 18 | from six import iteritems 19 | 20 | 21 | def token_repr(tok_type, string): 22 | """Returns a human-friendly representation of a token with the given type and string.""" 23 | # repr() prefixes unicode with 'u' on Python2 but not Python3; strip it out for consistency. 24 | return '%s:%s' % (token.tok_name[tok_type], repr(string).lstrip('u')) 25 | 26 | 27 | class Token(collections.namedtuple('Token', 'type string start end line index startpos endpos')): 28 | """ 29 | TokenInfo is an 8-tuple containing the same 5 fields as the tokens produced by the tokenize 30 | module, and 3 additional ones useful for this module: 31 | 32 | - [0] .type Token type (see token.py) 33 | - [1] .string Token (a string) 34 | - [2] .start Starting (row, column) indices of the token (a 2-tuple of ints) 35 | - [3] .end Ending (row, column) indices of the token (a 2-tuple of ints) 36 | - [4] .line Original line (string) 37 | - [5] .index Index of the token in the list of tokens that it belongs to. 38 | - [6] .startpos Starting character offset into the input text. 39 | - [7] .endpos Ending character offset into the input text. 40 | """ 41 | def __str__(self): 42 | return token_repr(self.type, self.string) 43 | 44 | 45 | def match_token(token, tok_type, tok_str=None): 46 | """Returns true if token is of the given type and, if a string is given, has that string.""" 47 | return token.type == tok_type and (tok_str is None or token.string == tok_str) 48 | 49 | 50 | def expect_token(token, tok_type, tok_str=None): 51 | """ 52 | Verifies that the given token is of the expected type. If tok_str is given, the token string 53 | is verified too. If the token doesn't match, raises an informative ValueError. 54 | """ 55 | if not match_token(token, tok_type, tok_str): 56 | raise ValueError("Expected token %s, got %s on line %s col %s" % ( 57 | token_repr(tok_type, tok_str), str(token), 58 | token.start[0], token.start[1] + 1)) 59 | 60 | 61 | def iter_children(node): 62 | """ 63 | Yields all direct children of a AST node, skipping children that are singleton nodes. 64 | """ 65 | return iter_children_astroid(node) if hasattr(node, 'get_children') else iter_children_ast(node) 66 | 67 | 68 | def iter_children_func(node): 69 | """ 70 | Returns a slightly more optimized function to use in place of ``iter_children``, depending on 71 | whether ``node`` is from ``ast`` or from the ``astroid`` module. 72 | """ 73 | return iter_children_astroid if hasattr(node, 'get_children') else iter_children_ast 74 | 75 | 76 | def iter_children_astroid(node): 77 | # Don't attempt to process children of JoinedStr nodes, which we can't fully handle yet. 78 | if is_joined_str(node): 79 | return [] 80 | 81 | return node.get_children() 82 | 83 | 84 | SINGLETONS = {c for n, c in iteritems(ast.__dict__) if isinstance(c, type) and 85 | issubclass(c, (ast.expr_context, ast.boolop, ast.operator, ast.unaryop, ast.cmpop))} 86 | 87 | def iter_children_ast(node): 88 | # Don't attempt to process children of JoinedStr nodes, which we can't fully handle yet. 89 | if is_joined_str(node): 90 | return 91 | 92 | for child in ast.iter_child_nodes(node): 93 | # Skip singleton children; they don't reflect particular positions in the code and break the 94 | # assumptions about the tree consisting of distinct nodes. Note that collecting classes 95 | # beforehand and checking them in a set is faster than using isinstance each time. 96 | if child.__class__ not in SINGLETONS: 97 | yield child 98 | 99 | 100 | stmt_class_names = {n for n, c in iteritems(ast.__dict__) 101 | if isinstance(c, type) and issubclass(c, ast.stmt)} 102 | expr_class_names = ({n for n, c in iteritems(ast.__dict__) 103 | if isinstance(c, type) and issubclass(c, ast.expr)} | 104 | {'AssignName', 'DelName', 'Const', 'AssignAttr', 'DelAttr'}) 105 | 106 | # These feel hacky compared to isinstance() but allow us to work with both ast and astroid nodes 107 | # in the same way, and without even importing astroid. 108 | def is_expr(node): 109 | """Returns whether node is an expression node.""" 110 | return node.__class__.__name__ in expr_class_names 111 | 112 | def is_stmt(node): 113 | """Returns whether node is a statement node.""" 114 | return node.__class__.__name__ in stmt_class_names 115 | 116 | def is_module(node): 117 | """Returns whether node is a module node.""" 118 | return node.__class__.__name__ == 'Module' 119 | 120 | def is_joined_str(node): 121 | """Returns whether node is a JoinedStr node, used to represent f-strings.""" 122 | # At the moment, nodes below JoinedStr have wrong line/col info, and trying to process them only 123 | # leads to errors. 124 | return node.__class__.__name__ == 'JoinedStr' 125 | 126 | 127 | # Sentinel value used by visit_tree(). 128 | _PREVISIT = object() 129 | 130 | def visit_tree(node, previsit, postvisit): 131 | """ 132 | Scans the tree under the node depth-first using an explicit stack. It avoids implicit recursion 133 | via the function call stack to avoid hitting 'maximum recursion depth exceeded' error. 134 | 135 | It calls ``previsit()`` and ``postvisit()`` as follows: 136 | 137 | * ``previsit(node, par_value)`` - should return ``(par_value, value)`` 138 | ``par_value`` is as returned from ``previsit()`` of the parent. 139 | 140 | * ``postvisit(node, par_value, value)`` - should return ``value`` 141 | ``par_value`` is as returned from ``previsit()`` of the parent, and ``value`` is as 142 | returned from ``previsit()`` of this node itself. The return ``value`` is ignored except 143 | the one for the root node, which is returned from the overall ``visit_tree()`` call. 144 | 145 | For the initial node, ``par_value`` is None. Either ``previsit`` and ``postvisit`` may be None. 146 | """ 147 | if not previsit: 148 | previsit = lambda node, pvalue: (None, None) 149 | if not postvisit: 150 | postvisit = lambda node, pvalue, value: None 151 | 152 | iter_children = iter_children_func(node) 153 | done = set() 154 | ret = None 155 | stack = [(node, None, _PREVISIT)] 156 | while stack: 157 | current, par_value, value = stack.pop() 158 | if value is _PREVISIT: 159 | assert current not in done # protect againt infinite loop in case of a bad tree. 160 | done.add(current) 161 | 162 | pvalue, post_value = previsit(current, par_value) 163 | stack.append((current, par_value, post_value)) 164 | 165 | # Insert all children in reverse order (so that first child ends up on top of the stack). 166 | ins = len(stack) 167 | for n in iter_children(current): 168 | stack.insert(ins, (n, pvalue, _PREVISIT)) 169 | else: 170 | ret = postvisit(current, par_value, value) 171 | return ret 172 | 173 | 174 | 175 | def walk(node): 176 | """ 177 | Recursively yield all descendant nodes in the tree starting at ``node`` (including ``node`` 178 | itself), using depth-first pre-order traversal (yieling parents before their children). 179 | 180 | This is similar to ``ast.walk()``, but with a different order, and it works for both ``ast`` and 181 | ``astroid`` trees. Also, as ``iter_children()``, it skips singleton nodes generated by ``ast``. 182 | """ 183 | iter_children = iter_children_func(node) 184 | done = set() 185 | stack = [node] 186 | while stack: 187 | current = stack.pop() 188 | assert current not in done # protect againt infinite loop in case of a bad tree. 189 | done.add(current) 190 | 191 | yield current 192 | 193 | # Insert all children in reverse order (so that first child ends up on top of the stack). 194 | # This is faster than building a list and reversing it. 195 | ins = len(stack) 196 | for c in iter_children(current): 197 | stack.insert(ins, c) 198 | 199 | 200 | def replace(text, replacements): 201 | """ 202 | Replaces multiple slices of text with new values. This is a convenience method for making code 203 | modifications of ranges e.g. as identified by ``ASTTokens.get_text_range(node)``. Replacements is 204 | an iterable of ``(start, end, new_text)`` tuples. 205 | 206 | For example, ``replace("this is a test", [(0, 4, "X"), (8, 1, "THE")])`` produces 207 | ``"X is THE test"``. 208 | """ 209 | p = 0 210 | parts = [] 211 | for (start, end, new_text) in sorted(replacements): 212 | parts.append(text[p:start]) 213 | parts.append(new_text) 214 | p = end 215 | parts.append(text[p:]) 216 | return ''.join(parts) 217 | 218 | 219 | class NodeMethods(object): 220 | """ 221 | Helper to get `visit_{node_type}` methods given a node's class and cache the results. 222 | """ 223 | def __init__(self): 224 | self._cache = {} 225 | 226 | def get(self, obj, cls): 227 | """ 228 | Using the lowercase name of the class as node_type, returns `obj.visit_{node_type}`, 229 | or `obj.visit_default` if the type-specific method is not found. 230 | """ 231 | method = self._cache.get(cls) 232 | if not method: 233 | name = "visit_" + cls.__name__.lower() 234 | method = getattr(obj, name, obj.visit_default) 235 | self._cache[cls] = method 236 | return method 237 | --------------------------------------------------------------------------------