From 2bfe9d70079b8d6191634bc2fb641747c04e6d83 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 26 Dec 2017 16:06:00 -0800 Subject: [PATCH 01/13] Update Python integration --- .travis.yml | 12 ++-- package.json | 4 +- .../python => python/patched}/astexport.py | 55 +++++-------------- python/prettier/__init__.py | 7 +++ python/prettier/parser.py | 22 ++++++++ .../vendor}/asttokens/__init__.py | 0 .../vendor}/asttokens/asttokens.py | 0 .../vendor}/asttokens/line_numbers.py | 0 .../vendor}/asttokens/mark_tokens.py | 0 .../vendor}/asttokens/util.py | 0 {vendor/python => python/vendor}/six.py | 0 src/parser.js | 36 +++++------- 12 files changed, 65 insertions(+), 71 deletions(-) rename {vendor/python => python/patched}/astexport.py (75%) create mode 100644 python/prettier/__init__.py create mode 100644 python/prettier/parser.py rename {vendor/python => python/vendor}/asttokens/__init__.py (100%) rename {vendor/python => python/vendor}/asttokens/asttokens.py (100%) rename {vendor/python => python/vendor}/asttokens/line_numbers.py (100%) rename {vendor/python => python/vendor}/asttokens/mark_tokens.py (100%) rename {vendor/python => python/vendor}/asttokens/util.py (100%) rename {vendor/python => python/vendor}/six.py (100%) diff --git a/.travis.yml b/.travis.yml index 62fa82a..66236c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,22 +4,22 @@ node_js: - 6 - 8 - 9 +env: + - PYTHON_VERSION=2.7.11 + - PYTHON_VERSION=3.6.3 cache: yarn: true directories: - node_modules - - /home/travis/.pyenv_cache + - /home/travis/.pyenv install: - yarn install before_install: - - export PYTHON_BUILD_CACHE_PATH="/home/travis/.pyenv_cache" - curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash - export PATH="/home/travis/.pyenv/bin:$PATH" - eval "$(pyenv init -)" - - eval "$(pyenv virtualenv-init -)" - - pyenv install -s 2.7.11 - - pyenv install -s 3.6.3 - - pyenv global 2.7.11 3.6.3 + - pyenv install -s $PYTHON_VERSION + - pyenv global $PYTHON_VERSION script: - yarn lint - yarn test -- --runInBand diff --git a/package.json b/package.json index 20cfb23..3e4ecdc 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "author": "Lucas Azzola <@azz>", "license": "MIT", "files": [ - "src", - "vendor" + "python", + "src" ], "engines": { "node": ">=6" diff --git a/vendor/python/astexport.py b/python/patched/astexport.py similarity index 75% rename from vendor/python/astexport.py rename to python/patched/astexport.py index cb8a818..e062c9a 100644 --- a/vendor/python/astexport.py +++ b/python/patched/astexport.py @@ -1,31 +1,8 @@ import ast -import fileinput -import json +import tokenize -import asttokens - -def export_json(atok, pretty_print=False): - dict = export_dict(atok) - dict['comments'] = [{ - 'ast_type': 'comment', - 'value': token.string, - 'start': token.startpos, - 'end': token.endpos, - } for token in atok.tokens if token.type == 57] - return json.dumps( - dict, - indent=4 if pretty_print else None, - sort_keys=True, - separators=(",", ": ") if pretty_print else (",", ":") - ) - - -def export_dict(atok): - return DictExportVisitor(atok).visit(atok.tree) - - -class DictExportVisitor: +class DictExportVisitor(object): ast_type_field = "ast_type" def __init__(self, atok): @@ -102,21 +79,17 @@ def visit_field_Num_n(self, val): } -def parse(source): - assert (isinstance(source, str)) - - atok = asttokens.ASTTokens(source, parse=True) - - return atok - - -def main(): - source = "".join(fileinput.input()) - - tree = parse(source) - json = export_json(tree, True) - print(json) +def export(atok): + exported_ast = DictExportVisitor(atok).visit(atok.tree) + exported_ast['comments'] = [ + { + 'ast_type': 'comment', + 'value': token.string, + 'start': token.startpos, + 'end': token.endpos, + } + for token in atok.tokens if token.type == tokenize.COMMENT + ] -if __name__ == '__main__': - main() + return exported_ast diff --git a/python/prettier/__init__.py b/python/prettier/__init__.py new file mode 100644 index 0000000..12784ba --- /dev/null +++ b/python/prettier/__init__.py @@ -0,0 +1,7 @@ +import os +import sys + +base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +sys.path.insert(0, os.path.join(base_dir, 'vendor')) +sys.path.insert(0, os.path.join(base_dir, 'patched')) diff --git a/python/prettier/parser.py b/python/prettier/parser.py new file mode 100644 index 0000000..c634ca4 --- /dev/null +++ b/python/prettier/parser.py @@ -0,0 +1,22 @@ +import json +import sys + +import astexport +import asttokens + + +def main(): + source = sys.stdin.read() + atok = asttokens.ASTTokens(source, parse=True) + + exported_ast = astexport.export(atok) + print(json.dumps( + exported_ast, + indent=4, + sort_keys=True, + separators=(',', ': '), + )) + + +if __name__ == '__main__': + main() diff --git a/vendor/python/asttokens/__init__.py b/python/vendor/asttokens/__init__.py similarity index 100% rename from vendor/python/asttokens/__init__.py rename to python/vendor/asttokens/__init__.py diff --git a/vendor/python/asttokens/asttokens.py b/python/vendor/asttokens/asttokens.py similarity index 100% rename from vendor/python/asttokens/asttokens.py rename to python/vendor/asttokens/asttokens.py diff --git a/vendor/python/asttokens/line_numbers.py b/python/vendor/asttokens/line_numbers.py similarity index 100% rename from vendor/python/asttokens/line_numbers.py rename to python/vendor/asttokens/line_numbers.py diff --git a/vendor/python/asttokens/mark_tokens.py b/python/vendor/asttokens/mark_tokens.py similarity index 100% rename from vendor/python/asttokens/mark_tokens.py rename to python/vendor/asttokens/mark_tokens.py diff --git a/vendor/python/asttokens/util.py b/python/vendor/asttokens/util.py similarity index 100% rename from vendor/python/asttokens/util.py rename to python/vendor/asttokens/util.py diff --git a/vendor/python/six.py b/python/vendor/six.py similarity index 100% rename from vendor/python/six.py rename to python/vendor/six.py diff --git a/src/parser.js b/src/parser.js index eca5103..55e65be 100644 --- a/src/parser.js +++ b/src/parser.js @@ -3,31 +3,23 @@ const spawnSync = require("child_process").spawnSync; const path = require("path"); -function parseText(text, pythonExecutable) { - const executionResult = spawnSync( - pythonExecutable, - [path.join(__dirname, "../vendor/python/astexport.py")], - { - input: text - } - ); - - const error = executionResult.stderr.toString(); - - if (error) { - throw new Error(error); +function parse(text) { + const executionResult = spawnSync("python", ["-m", "prettier.parser"], { + env: { + PYTHONPATH: [ + path.join(__dirname, "../python"), + process.env.PYTHONPATH + ].join(path.delimiter) + }, + input: text + }); + + if (executionResult.status) { + throw new Error(executionResult.stderr.toString()); } - return executionResult; -} - -function parse(text, parsers, opts) { - const pythonExectuable = `python${opts.pythonVersion == "2" ? "" : "3"}`; - const executionResult = parseText(text, pythonExectuable); - const res = executionResult.stdout.toString(); - const ast = JSON.parse(res); - return ast; + return JSON.parse(res); } module.exports = parse; From 8224c071584532965d14e0307274083f108a6f85 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 26 Dec 2017 16:08:58 -0800 Subject: [PATCH 02/13] Better JSON dumping --- python/prettier/parser.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/python/prettier/parser.py b/python/prettier/parser.py index c634ca4..571575e 100644 --- a/python/prettier/parser.py +++ b/python/prettier/parser.py @@ -10,12 +10,7 @@ def main(): atok = asttokens.ASTTokens(source, parse=True) exported_ast = astexport.export(atok) - print(json.dumps( - exported_ast, - indent=4, - sort_keys=True, - separators=(',', ': '), - )) + json.dump(exported_ast, sys.stdout, separators=(',', ':')) if __name__ == '__main__': From b7b8cf1500eca1b7471190cc58ffaaaebcdefbf3 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 26 Dec 2017 16:38:48 -0800 Subject: [PATCH 03/13] Fix tests --- package.json | 7 +- src/parser.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_args_mixed/jsfmt.spec.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_async_func/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_aug_assign/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_await/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_f_strings/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python3_kwargs_only/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_args/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_args_mixed/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +- tests/python_assert/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 21 +- tests/python_assign/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 57 +- tests/python_aug_assign/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +- tests/python_bool_op/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 13 +- tests/python_call/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 13 +- tests/python_class/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/python_comments/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 40 +- tests/python_compare/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 27 +- tests/python_decorators/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_default_args/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 34 +- tests/python_dict/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 706 +----------------- tests/python_expressions/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 9 +- tests/python_float/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_for/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 15 +- tests/python_for_else/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_for_kv/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_hello/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 23 +- tests/python_if/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 29 +- tests/python_import/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_kwargs/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_lambdas/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +- tests/python_list_comp/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 14 +- tests/python_long/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 29 +- tests/python_nested_if/jsfmt.spec.js | 3 +- tests/python_nested_if/nested_if.py | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +- tests/python_not_in/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 15 +- tests/python_pass/jsfmt.spec.js | 3 +- tests/python_pass/pass.py | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 17 +- tests/python_return/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 9 +- tests/python_starred/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 19 +- tests/python_strings/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 39 +- tests/python_subscript/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 22 +- tests/python_tagged_strings/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 39 +- tests/python_try/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 11 +- tests/python_while/jsfmt.spec.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 24 +- tests/python_with/jsfmt.spec.js | 3 +- tests_config/run_spec.js | 22 +- yarn.lock | 2 +- 90 files changed, 115 insertions(+), 1418 deletions(-) diff --git a/package.json b/package.json index 3e4ecdc..c0c220e 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,16 @@ "eslint-plugin-jest": "^21.5.0", "eslint-plugin-prettier": "^2.4.0", "jest": "^21.1.0", - "jest-runner-eslint": "^0.3.0" + "jest-runner-eslint": "^0.3.0", + "semver": "^5.4.1" }, "scripts": { "lint": "prettier src/**/*.js --list-different", "test": "jest" }, "jest": { - "projects": ["/jest.*.config.js"] + "projects": [ + "/jest.*.config.js" + ] } } diff --git a/src/parser.js b/src/parser.js index 55e65be..7a6c515 100644 --- a/src/parser.js +++ b/src/parser.js @@ -6,6 +6,7 @@ const path = require("path"); function parse(text) { const executionResult = spawnSync("python", ["-m", "prettier.parser"], { env: { + PATH: process.env.PATH, PYTHONPATH: [ path.join(__dirname, "../python"), process.env.PYTHONPATH diff --git a/tests/python3_args_mixed/__snapshots__/jsfmt.spec.js.snap b/tests/python3_args_mixed/__snapshots__/jsfmt.spec.js.snap index ea62cd9..c64e347 100644 --- a/tests/python3_args_mixed/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_args_mixed/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`args_mixed.py 1`] = ` def hello(a, *, example=False, **kwargs): print("hello world", example) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(a, *, example=False, **kwargs): print("hello world", example) diff --git a/tests/python3_args_mixed/jsfmt.spec.js b/tests/python3_args_mixed/jsfmt.spec.js index a535402..8552785 100644 --- a/tests/python3_args_mixed/jsfmt.spec.js +++ b/tests/python3_args_mixed/jsfmt.spec.js @@ -1,3 +1 @@ -run_spec(__dirname, ["python"], { - pythonVersion: "3" -}); +run_spec(__dirname, ["python"], ">=3"); diff --git a/tests/python3_async_func/__snapshots__/jsfmt.spec.js.snap b/tests/python3_async_func/__snapshots__/jsfmt.spec.js.snap index 1263031..c7c02d6 100644 --- a/tests/python3_async_func/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_async_func/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`async_func.py 1`] = ` async def hello(x, a=123, b = 456): print("hello world", a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ async def hello(x, a=123, b=456): print("hello world", a) diff --git a/tests/python3_async_func/jsfmt.spec.js b/tests/python3_async_func/jsfmt.spec.js index 007404f..8552785 100644 --- a/tests/python3_async_func/jsfmt.spec.js +++ b/tests/python3_async_func/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], ">=3"); diff --git a/tests/python3_aug_assign/__snapshots__/jsfmt.spec.js.snap b/tests/python3_aug_assign/__snapshots__/jsfmt.spec.js.snap index 5ada147..c7c58bf 100644 --- a/tests/python3_aug_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_aug_assign/__snapshots__/jsfmt.spec.js.snap @@ -2,7 +2,7 @@ exports[`aug_assign.py 1`] = ` a @= 1 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a @= 1 `; diff --git a/tests/python3_aug_assign/jsfmt.spec.js b/tests/python3_aug_assign/jsfmt.spec.js index 007404f..1aef220 100644 --- a/tests/python3_aug_assign/jsfmt.spec.js +++ b/tests/python3_aug_assign/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], ">=3.5"); diff --git a/tests/python3_await/__snapshots__/jsfmt.spec.js.snap b/tests/python3_await/__snapshots__/jsfmt.spec.js.snap index 5d6a33c..88aebd1 100644 --- a/tests/python3_await/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_await/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,7 @@ async def example(): 'image': image, 'username': data.user.screen_name, })) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ async def example(): await channel.put(json.dumps({ "text": data.text, diff --git a/tests/python3_await/jsfmt.spec.js b/tests/python3_await/jsfmt.spec.js index 007404f..1aef220 100644 --- a/tests/python3_await/jsfmt.spec.js +++ b/tests/python3_await/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], ">=3.5"); diff --git a/tests/python3_f_strings/__snapshots__/jsfmt.spec.js.snap b/tests/python3_f_strings/__snapshots__/jsfmt.spec.js.snap index 2df79ef..f85a40c 100644 --- a/tests/python3_f_strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_f_strings/__snapshots__/jsfmt.spec.js.snap @@ -6,7 +6,7 @@ precision = 4 value = decimal.Decimal("12.34567") f"result: {value:{width}.{precision}}" rf"result: {value:{width}.{precision}}" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ width = 10 precision = 4 diff --git a/tests/python3_f_strings/jsfmt.spec.js b/tests/python3_f_strings/jsfmt.spec.js index 007404f..546fe0a 100644 --- a/tests/python3_f_strings/jsfmt.spec.js +++ b/tests/python3_f_strings/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], ">=3.6"); diff --git a/tests/python3_kwargs_only/__snapshots__/jsfmt.spec.js.snap b/tests/python3_kwargs_only/__snapshots__/jsfmt.spec.js.snap index 9123719..13bcd07 100644 --- a/tests/python3_kwargs_only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python3_kwargs_only/__snapshots__/jsfmt.spec.js.snap @@ -3,7 +3,7 @@ exports[`kwargs_only.py 1`] = ` def hello(a, *, delete=False): print("hello world", delete) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(a, *, delete=False): print("hello world", delete) diff --git a/tests/python3_kwargs_only/jsfmt.spec.js b/tests/python3_kwargs_only/jsfmt.spec.js index 007404f..8552785 100644 --- a/tests/python3_kwargs_only/jsfmt.spec.js +++ b/tests/python3_kwargs_only/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], ">=3"); diff --git a/tests/python_args/__snapshots__/jsfmt.spec.js.snap b/tests/python_args/__snapshots__/jsfmt.spec.js.snap index f3eb1e1..290efa8 100644 --- a/tests/python_args/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_args/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`args.py 1`] = ` def hello(*args): print("hello world", args) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def hello(*args): - print("hello world", args) - -`; - -exports[`args.py 2`] = ` -def hello(*args): - print("hello world", args) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(*args): print("hello world", args) diff --git a/tests/python_args/jsfmt.spec.js b/tests/python_args/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_args/jsfmt.spec.js +++ b/tests/python_args/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_args_mixed/__snapshots__/jsfmt.spec.js.snap b/tests/python_args_mixed/__snapshots__/jsfmt.spec.js.snap index 95e9635..2c60949 100644 --- a/tests/python_args_mixed/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_args_mixed/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`args_mixed.py 1`] = ` def hello(a, example=False, **kwargs): print("hello world", example) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def hello(a, example=False, **kwargs): - print("hello world", example) - -`; - -exports[`args_mixed.py 2`] = ` -def hello(a, example=False, **kwargs): - print("hello world", example) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(a, example=False, **kwargs): print("hello world", example) diff --git a/tests/python_args_mixed/jsfmt.spec.js b/tests/python_args_mixed/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_args_mixed/jsfmt.spec.js +++ b/tests/python_args_mixed/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_assert/__snapshots__/jsfmt.spec.js.snap b/tests/python_assert/__snapshots__/jsfmt.spec.js.snap index 14b4aa7..7536453 100644 --- a/tests/python_assert/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_assert/__snapshots__/jsfmt.spec.js.snap @@ -3,17 +3,7 @@ exports[`assert.py 1`] = ` assert 3 + 3 assert False, 'message' -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -assert 3 + 3 - -assert False, "message" - -`; - -exports[`assert.py 2`] = ` -assert 3 + 3 -assert False, 'message' -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assert 3 + 3 assert False, "message" diff --git a/tests/python_assert/jsfmt.spec.js b/tests/python_assert/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_assert/jsfmt.spec.js +++ b/tests/python_assert/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_assign/__snapshots__/jsfmt.spec.js.snap b/tests/python_assign/__snapshots__/jsfmt.spec.js.snap index 75d81e9..01451ac 100644 --- a/tests/python_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_assign/__snapshots__/jsfmt.spec.js.snap @@ -8,26 +8,7 @@ b = 14 a, b = b, a new_file_name = file_name[:-6] + extension -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = 12 - -b = 14 - -a, b = b, a - -new_file_name = file_name[:-6] + extension - -`; - -exports[`assign.py 2`] = ` -a = 12 - -b = 14 - -a, b = b, a - -new_file_name = file_name[:-6] + extension -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = 12 b = 14 diff --git a/tests/python_assign/jsfmt.spec.js b/tests/python_assign/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_assign/jsfmt.spec.js +++ b/tests/python_assign/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_aug_assign/__snapshots__/jsfmt.spec.js.snap b/tests/python_aug_assign/__snapshots__/jsfmt.spec.js.snap index 58781b4..29e091c 100644 --- a/tests/python_aug_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_aug_assign/__snapshots__/jsfmt.spec.js.snap @@ -26,62 +26,7 @@ a &= 1 a ^= 1 a |= 1 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = 10 - -a += 10 - -a -= 1 - -a *= 1 - -a /= 1 - -a //= 1 - -a %= 1 - -a **= 1 - -a <<= 1 - -a >>= 1 - -a &= 1 - -a ^= 1 - -a |= 1 - -`; - -exports[`aug_assign.py 2`] = ` -a = 10 - -a += 10 - -a -= 1 - -a *= 1 - -a /= 1 - -a //= 1 - -a %= 1 - -a **= 1 - -a <<= 1 - -a >>= 1 - -a &= 1 - -a ^= 1 - -a |= 1 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = 10 a += 10 diff --git a/tests/python_aug_assign/jsfmt.spec.js b/tests/python_aug_assign/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_aug_assign/jsfmt.spec.js +++ b/tests/python_aug_assign/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_bool_op/__snapshots__/jsfmt.spec.js.snap b/tests/python_bool_op/__snapshots__/jsfmt.spec.js.snap index bfd1fda..14e87b4 100644 --- a/tests/python_bool_op/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_bool_op/__snapshots__/jsfmt.spec.js.snap @@ -3,17 +3,7 @@ exports[`bool_op.py 1`] = ` data.retweeted or 'RT @' in data.text data.retweeted and 'RT @' in data.text -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -data.retweeted or "RT @" in data.text - -data.retweeted and "RT @" in data.text - -`; - -exports[`bool_op.py 2`] = ` -data.retweeted or 'RT @' in data.text -data.retweeted and 'RT @' in data.text -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ data.retweeted or "RT @" in data.text data.retweeted and "RT @" in data.text diff --git a/tests/python_bool_op/jsfmt.spec.js b/tests/python_bool_op/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_bool_op/jsfmt.spec.js +++ b/tests/python_bool_op/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_call/__snapshots__/jsfmt.spec.js.snap b/tests/python_call/__snapshots__/jsfmt.spec.js.snap index 629ab7a..37f558c 100644 --- a/tests/python_call/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_call/__snapshots__/jsfmt.spec.js.snap @@ -4,18 +4,7 @@ exports[`call.py 1`] = ` print(123) random.run(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -print(123) - -random.run(123) - -`; - -exports[`call.py 2`] = ` -print(123) - -random.run(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ print(123) random.run(123) diff --git a/tests/python_call/jsfmt.spec.js b/tests/python_call/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_call/jsfmt.spec.js +++ b/tests/python_call/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_class/__snapshots__/jsfmt.spec.js.snap b/tests/python_class/__snapshots__/jsfmt.spec.js.snap index 8c44bcd..67cfa07 100644 --- a/tests/python_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_class/__snapshots__/jsfmt.spec.js.snap @@ -4,18 +4,7 @@ exports[`class.py 1`] = ` class BankAccount(object): def __init__(self, initial_balance=0): self.balance = initial_balance -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class BankAccount(object): - def __init__(self, initial_balance=0): - self.balance = initial_balance - -`; - -exports[`class.py 2`] = ` -class BankAccount(object): - def __init__(self, initial_balance=0): - self.balance = initial_balance -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class BankAccount(object): def __init__(self, initial_balance=0): self.balance = initial_balance diff --git a/tests/python_class/jsfmt.spec.js b/tests/python_class/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_class/jsfmt.spec.js +++ b/tests/python_class/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_comments/__snapshots__/jsfmt.spec.js.snap b/tests/python_comments/__snapshots__/jsfmt.spec.js.snap index 3c1b4e3..fdb3004 100644 --- a/tests/python_comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_comments/__snapshots__/jsfmt.spec.js.snap @@ -14,7 +14,7 @@ if a: # a call( # a ) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if a: # a # b c diff --git a/tests/python_comments/jsfmt.spec.js b/tests/python_comments/jsfmt.spec.js index 3afccf9..147833d 100644 --- a/tests/python_comments/jsfmt.spec.js +++ b/tests/python_comments/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["python"]); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_compare/__snapshots__/jsfmt.spec.js.snap b/tests/python_compare/__snapshots__/jsfmt.spec.js.snap index 032d0d2..d767ba1 100644 --- a/tests/python_compare/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_compare/__snapshots__/jsfmt.spec.js.snap @@ -17,45 +17,7 @@ x != y x >= y x <= y -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -x = 10 - -y = 12 - -x < 11 < y < 100 - -x > y - -x < y - -x == y - -x != y - -x >= y - -x <= y - -`; - -exports[`compare.py 2`] = ` -x = 10 -y = 12 - -x < 11 < y < 100 - -x > y - -x < y - -x == y - -x != y - -x >= y - -x <= y -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ x = 10 y = 12 diff --git a/tests/python_compare/jsfmt.spec.js b/tests/python_compare/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_compare/jsfmt.spec.js +++ b/tests/python_compare/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_decorators/__snapshots__/jsfmt.spec.js.snap b/tests/python_decorators/__snapshots__/jsfmt.spec.js.snap index d7fd3ab..d7696aa 100644 --- a/tests/python_decorators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_decorators/__snapshots__/jsfmt.spec.js.snap @@ -11,32 +11,7 @@ class UserStream(EventStream): def tweet(self, data): if data.retweeted or 'RT @' in data.text: return -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@Client.event_stream -class UserStream(EventStream): - def stream_request(self): - return self.stream.statuses.filter.post(track="#europython,europython") - - @events.on_connect.handler - @events.on_tweet.handler - def tweet(self, data): - if data.retweeted or "RT @" in data.text: - return - -`; - -exports[`decorators.py 2`] = ` -@Client.event_stream -class UserStream(EventStream): - def stream_request(self): - return self.stream.statuses.filter.post(track="#europython,europython") - - @events.on_connect.handler - @events.on_tweet.handler - def tweet(self, data): - if data.retweeted or 'RT @' in data.text: - return -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Client.event_stream class UserStream(EventStream): def stream_request(self): diff --git a/tests/python_decorators/jsfmt.spec.js b/tests/python_decorators/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_decorators/jsfmt.spec.js +++ b/tests/python_decorators/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_default_args/__snapshots__/jsfmt.spec.js.snap b/tests/python_default_args/__snapshots__/jsfmt.spec.js.snap index f029ac2..29f1e5c 100644 --- a/tests/python_default_args/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_default_args/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`default_args.py 1`] = ` def hello(x, a=123, b = 456): print("hello world", a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def hello(x, a=123, b=456): - print("hello world", a) - -`; - -exports[`default_args.py 2`] = ` -def hello(x, a=123, b = 456): - print("hello world", a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(x, a=123, b=456): print("hello world", a) diff --git a/tests/python_default_args/jsfmt.spec.js b/tests/python_default_args/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_default_args/jsfmt.spec.js +++ b/tests/python_default_args/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_dict/__snapshots__/jsfmt.spec.js.snap b/tests/python_dict/__snapshots__/jsfmt.spec.js.snap index d1476a9..26803cb 100644 --- a/tests/python_dict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_dict/__snapshots__/jsfmt.spec.js.snap @@ -16,39 +16,7 @@ a = { 'g': 345, 'hhhhhhhhhhhhhh': 345, } -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = {"a": 123,"b": 345} - -a = { - "a": 123, - "b": 345, - "c": 345, - "d": 345, - "e": 345, - "f": 345, - "g": 345, - "hhhhhhhhhhhhhh": 345 -} - -`; - -exports[`dict.py 2`] = ` -a = { - "a": 123, - 'b': 345 -} - -a = { - "a": 123, - 'b': 345, - 'c': 345, - 'd': 345, - 'e': 345, - 'f': 345, - 'g': 345, - 'hhhhhhhhhhhhhh': 345, -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = {"a": 123,"b": 345} a = { diff --git a/tests/python_dict/jsfmt.spec.js b/tests/python_dict/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_dict/jsfmt.spec.js +++ b/tests/python_dict/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_expressions/__snapshots__/jsfmt.spec.js.snap b/tests/python_expressions/__snapshots__/jsfmt.spec.js.snap index e83f2ae..a0b0ec7 100644 --- a/tests/python_expressions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_expressions/__snapshots__/jsfmt.spec.js.snap @@ -334,711 +334,7 @@ a=1;a<<=2 a=1;a&=2 a=1;a^=2 a=1;a|=2 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -0 - -7 - --3 - -24 - -1 - -3.9 - --3.6 - -18000000000000000000 - -90000000000000 - -90000000000000 - -x = a + 1 - -x = 1 - a - -x = a * b - -x = a ** 2 - -x = a / b - -x = a & b - -x = a | b - -x = a ^ b - -x = a // b - -x = a * b + 1 - -x = a + 1 * b - -x = a * b / c - -x, y, z = 1, 2, 3 - -l[0] - -k[v] - -m[a, b] - -a.b.c[d] - -file("some.txt").read() - -a[0].read() - -a[1:1].read() - -f("foo")("bar")("spam") - -f("foo")("bar")("spam").read()[0] - -a.b[0][0] - -a.b[0][0].pop()[0].push("bar")("baz").spam - -a.b[0].read()[1][2].foo().spam()[0].bar - -a ** 2 - -a ** 2 ** 2 - -a.b[0] ** 2 - -a.b[0].read()[1][2].foo().spam()[0].bar ** 2 - -l[start:end] = l2 - -[a, b] = c - -[a, (b, c), d] = e - -a, (b, c), d = e - -1 if True else 2 - -1 if False else 2 - -l = func() - -l = func(10) - -l = func(10, 12, a, b=c) - -e = l.pop(3) - -e = k.l.pop(3) - -l = [] - -l = [1, 2, 3] - -l = [i for i in range(10)] - -l = [i for i in range(10) if i % 2 == 0] - -l = [i for i in range(10) if i % 2 == 0 or i % 2 == 1] - -l = [i for i in range(10) if i % 2 == 0 and i % 2 == 1] - -l = [i for j in range(10) for i in range(j)] - -l = [i for j in range(10) for i in range(j) if j % 2 == 0] - -l = [i for j in range(10) for i in range(j) if j % 2 == 0 and i % 2 == 0] - -l = [i for j in k if j % 2 == 0 j * 2 < 20 for i in j if i % 2 == 0] - -l = {a: b,"c": 0} - -l = {} - -f = lambda x: x + 1 - -f = lambda x, y: x + y - -f = lambda x, y=1, z=t: x + y - -f = lambda x, y=1, z=t, *args, **kwargs: x + y - -f = lambda x, y=1, z=t, *args: x + y - -f = lambda x, y=1, z=t, **kwargs: x + y - -f = lambda : 1 - -f = lambda *args: 1 - -f = lambda **kwargs: 1 - -a < b - -a > b - -a not in b - -a is not b - -a in b - -a is b - -3 < x < 5 - -a < b < c < d - -a = b - -c = d - -a.b = 2 - -x = a.b - -l[1:2] - -l[:2] - -l[::1] - -l[:1:2] - -l[1::2] - -l[0:1:2] - -a.b.l[1:2] - -a.b.l[0:1:2] - -import os - -import sys, os - -import os.path - -import os.path, sys - -import sys, os.path as osp - -import os.path as osp - -import os.path as osp, sys as _sys - -import a.b.c.d - -import a.b.c.d as abcd - -from os import path - -from os import path, system - -from os import path, system - -from os import path as P, system as S - -from os import * - -if a == 1: - a += 2 - -if a == 1: - a += 2 -elif a == 2: - a += 3 -else: - a += 4 - -assert False - -assert a == 1 - -assert a == 1 and b == 2 - -assert a == 1 and b == 2, "assertion failed" - -raise - -raise ValueError - -raise ValueError("error") - -try: - a - - b -except: - pass - -try: - a - - b -except NameError: - pass - -def f(): - return 1 - -def f(x): - return x + 1 - -def f(x, y): - return x + y - -def f(x, y=1, z=t): - return x + y - -def f(x, y=1, z=t, *args, **kwargs): - return x + y - -def f(x, y=1, z=t, *args): - return x + y - -def f(x, y=1, z=t, **kwargs): - return x + y - -def f(*args): - return 1 - -def f(**kwargs): - return 1 - -class Pdb(bdb.Bdb,cmd.Cmd): - pass - -class A: - pass - -def foo(): - return 1 - -class Foo: - pass - -class Foo: - "foo" - -def foo(): - """foo docstring""" - - return 1 - -def foo(): - """foo docstring""" - - a = 1 - - """bar""" - - return a - -def f(): - return - -def f(): - return 1 - -def f(): - return a.b - -def f(): - return a - -def f(): - return a, b, c, d - -a = 1 - -a += 2 - -a = 1 - -a -= 2 - -a = 1 - -a *= 2 - -a = 1 - -a /= 2 - -a = 1 - -a //= 2 - -a = 1 - -a %= 2 - -a = 1 - -a **= 2 - -a = 1 - -a >>= 2 - -a = 1 - -a <<= 2 - -a = 1 - -a &= 2 - -a = 1 - -a ^= 2 - -a = 1 - -a |= 2 - -`; - -exports[`expressions.py 2`] = ` -# https://bitbucket.org/pypy/pypy/src/f9e4e9cb7b1949c548cb16ab1520e7ebced75dda/pypy/interpreter/pyparser/test/expressions.py - -0 -7 --3 -# 053 -0x18 -# 14L -1.0 -3.9 --3.6 -1.8e19 -90000000000000 -90000000000000. -# 3j - -x = a + 1 -x = 1 - a -x = a * b -x = a ** 2 -x = a / b -x = a & b -x = a | b -x = a ^ b -x = a // b -x = a * b + 1 -x = a + 1 * b -x = a * b / c -# x = a * (1 + c) -x, y, z = 1, 2, 3 -# x = 'a' 'b' 'c' -# del foo -# del foo[bar] -# del foo.bar -l[0] -k[v,] -m[a,b] -a.b.c[d] -file('some.txt').read() -a[0].read() -a[1:1].read() -f('foo')('bar')('spam') -f('foo')('bar')('spam').read()[0] -a.b[0][0] -# a.b[0][:] -# a.b[0][::] -a.b[0][0].pop()[0].push('bar')('baz').spam -a.b[0].read()[1][2].foo().spam()[0].bar -a**2 -a**2**2 -a.b[0]**2 -a.b[0].read()[1][2].foo().spam()[0].bar ** 2 -l[start:end] = l2 -# l[::] = l2 -# a = \`s\` -# a = \`1 + 2 + f(3, 4)\` -[a, b] = c -# (a, b) = c -[a, (b,c), d] = e -a, (b, c), d = e - -1 if True else 2 -1 if False else 2 - -l = func() -l = func(10) -# l = func(10, 12, a, b=c, *args) -# l = func(10, 12, a, b=c, **kwargs) -# l = func(10, 12, a, b=c, *args, **kwargs) -l = func(10, 12, a, b=c) -e = l.pop(3) -e = k.l.pop(3) - -l = [] -l = [1, 2, 3] -l = [i for i in range(10)] -l = [i for i in range(10) if i%2 == 0] -l = [i for i in range(10) if i%2 == 0 or i%2 == 1] -l = [i for i in range(10) if i%2 == 0 and i%2 == 1] -l = [i for j in range(10) for i in range(j)] -l = [i for j in range(10) for i in range(j) if j%2 == 0] -l = [i for j in range(10) for i in range(j) if j%2 == 0 and i%2 == 0] -# l = [(a, b) for (a,b,c) in l2] -# l = [{a:b} for (a,b,c) in l2] -l = [i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0] - -# l = (i for i in j) -# l = (i for i in j if i%2 == 0) -# l = (i for j in k for i in j) -# l = (i for j in k for i in j if j%2==0) -# l = (i for j in k if j%2 == 0 if j*2 < 20 for i in j if i%2==0) -# l = (i for i in [ j*2 for j in range(10) ] ) -# l = [i for i in ( j*2 for j in range(10) ) ] -# l = (i for i in [ j*2 for j in ( k*3 for k in range(10) ) ] ) -# l = [i for j in ( j*2 for j in [ k*3 for k in range(10) ] ) ] -# l = f(i for i in j) - -l = {a : b, 'c' : 0} -l = {} - -f = lambda x: x+1 -f = lambda x,y: x+y -f = lambda x,y=1,z=t: x+y -f = lambda x,y=1,z=t,*args,**kwargs: x+y -f = lambda x,y=1,z=t,*args: x+y -f = lambda x,y=1,z=t,**kwargs: x+y -f = lambda: 1 -f = lambda *args: 1 -f = lambda **kwargs: 1 - -a < b -a > b -a not in b -a is not b -a in b -a is b -3 < x < 5 -# (3 < x) < 5 -a < b < c < d -# (a < b) < (c < d) -# a < (b < c) < d - -a = b; c = d; -# a = b = c = d - -a.b = 2 -x = a.b - -# l[:] -# l[::] -l[1:2] -# l[1:] -l[:2] -# l[1::] -# l[:1:] -l[::1] -# l[1:2:] -l[:1:2] -l[1::2] -l[0:1:2] -# a.b.l[:] -a.b.l[1:2] -# a.b.l[1:] -# a.b.l[:2] -a.b.l[0:1:2] -# a[1:2:3, 100] -# a[:2:3, 100] -# a[1::3, 100,] -# a[1:2:, 100] -# a[1:2, 100] -# a[1:, 100,] -# a[:2, 100] -# a[:, 100] -# a[100, 1:2:3,] -# a[100, :2:3] -# a[100, 1::3] -# a[100, 1:2:,] -# a[100, 1:2] -# a[100, 1:] -# a[100, :2,] -# a[100, :] -# -import os -import sys, os -import os.path -import os.path, sys -import sys, os.path as osp -import os.path as osp -import os.path as osp, sys as _sys -import a.b.c.d -import a.b.c.d as abcd -from os import path -from os import path, system - -from os import path, system -from os import path as P, system as S -# from os import (path as P, system as S,) -from os import * - -if a == 1: a+= 2 -if a == 1: - a += 2 -elif a == 2: - a += 3 -else: - a += 4 -# if a and not b == c: pass -# if a and not not not b == c: pass -# if 0: print 'foo' - -assert False -assert a == 1 -assert a == 1 and b == 2 -assert a == 1 and b == 2, "assertion failed" - -# exec a -# exec "a=b+3" -# exec a in f() -# exec a in f(), g() - -# print -# print a -# print a, -# print a, b -# print a, "b", c -# print >> err -# print >> err, "error" -# print >> err, "error", -# print >> err, "error", a - -# global a -# global a,b,c - -raise -raise ValueError -raise ValueError("error") -# raise ValueError, "error" -# raise ValueError, "error", foo - -try: - a - b -except: - pass -try: - a - b -except NameError: - pass -# try: -# a -# b -# except NameError, err: -# pass -# try: -# a -# b -# except (NameError, ValueError): -# pass -# try: -# a -# b -# except (NameError, ValueError), err: -# pass -# try: -# a -# except NameError, err: -# pass -# except ValueError, err: -# pass -# def f(): -# try: -# a -# except NameError, err: -# a = 1 -# b = 2 -# except ValueError, err: -# a = 2 -# return a -# try: -# a -# except NameError, err: -# a = 1 -# except ValueError, err: -# a = 2 -# else: -# a += 3 -# try: -# a -# finally: -# b -# def f(): -# try: -# return a -# finally: -# a = 3 -# return 1 - -def f(): return 1 -def f(x): return x+1 -def f(x,y): return x+y -def f(x,y=1,z=t): return x+y -def f(x,y=1,z=t,*args,**kwargs): return x+y -def f(x,y=1,z=t,*args): return x+y -def f(x,y=1,z=t,**kwargs): return x+y -def f(*args): return 1 -def f(**kwargs): return 1 -# def f(t=()): pass -# def f(a, b, (c, d), e): pass -# def f(a, b, (c, (d, e), f, (g, h))): pass -# def f(a, b, (c, (d, e), f, (g, h)), i): pass -# def f((a)): pass - -class Pdb(bdb.Bdb, cmd.Cmd): pass -class A: pass - -def foo(): return 1 -class Foo: pass -class Foo: "foo" -def foo(): - """foo docstring""" - return 1 - -def foo(): - """foo docstring""" - a = 1 - """bar""" - return a - -# def foo(): -# """doc"""; print 1 -# a=1 - -# """Docstring""";print 1 - -def f(): return -def f(): return 1 -def f(): return a.b -def f(): return a -def f(): return a,b,c,d - -a=1;a+=2 -a=1;a-=2 -a=1;a*=2 -a=1;a/=2 -a=1;a//=2 -a=1;a%=2 -a=1;a**=2 -a=1;a>>=2 -a=1;a<<=2 -a=1;a&=2 -a=1;a^=2 -a=1;a|=2 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # https://bitbucket.org/pypy/pypy/src/f9e4e9cb7b1949c548cb16ab1520e7ebced75dda/pypy/interpreter/pyparser/test/expressions.py 0 diff --git a/tests/python_expressions/jsfmt.spec.js b/tests/python_expressions/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_expressions/jsfmt.spec.js +++ b/tests/python_expressions/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_float/__snapshots__/jsfmt.spec.js.snap b/tests/python_float/__snapshots__/jsfmt.spec.js.snap index b18bcac..4271873 100644 --- a/tests/python_float/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_float/__snapshots__/jsfmt.spec.js.snap @@ -2,14 +2,7 @@ exports[`float.py 1`] = ` b = 3.75 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -b = 3.75 - -`; - -exports[`float.py 2`] = ` -b = 3.75 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ b = 3.75 `; diff --git a/tests/python_float/jsfmt.spec.js b/tests/python_float/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_float/jsfmt.spec.js +++ b/tests/python_float/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_for/__snapshots__/jsfmt.spec.js.snap b/tests/python_for/__snapshots__/jsfmt.spec.js.snap index 4686d8d..279a0a0 100644 --- a/tests/python_for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_for/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`for.py 1`] = ` for x in range(10): print(x) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -for x in range(10): - print(x) - -`; - -exports[`for.py 2`] = ` -for x in range(10): - print(x) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for x in range(10): print(x) diff --git a/tests/python_for/jsfmt.spec.js b/tests/python_for/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_for/jsfmt.spec.js +++ b/tests/python_for/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_for_else/__snapshots__/jsfmt.spec.js.snap b/tests/python_for_else/__snapshots__/jsfmt.spec.js.snap index 0eb7894..4a48cbd 100644 --- a/tests/python_for_else/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_for_else/__snapshots__/jsfmt.spec.js.snap @@ -5,20 +5,7 @@ for x in range(10): print(x) else: print(x) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -for x in range(10): - print(x) -else: - print(x) - -`; - -exports[`for_else.py 2`] = ` -for x in range(10): - print(x) -else: - print(x) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for x in range(10): print(x) else: diff --git a/tests/python_for_else/jsfmt.spec.js b/tests/python_for_else/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_for_else/jsfmt.spec.js +++ b/tests/python_for_else/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_for_kv/__snapshots__/jsfmt.spec.js.snap b/tests/python_for_kv/__snapshots__/jsfmt.spec.js.snap index 4720e93..5334ed7 100644 --- a/tests/python_for_kv/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_for_kv/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`for_kw.py 1`] = ` for a, b in [(1, 2), (1, 2)]: print(a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -for a, b in [(1, 2), (1, 2)]: - print(a) - -`; - -exports[`for_kw.py 2`] = ` -for a, b in [(1, 2), (1, 2)]: - print(a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for a, b in [(1, 2), (1, 2)]: print(a) diff --git a/tests/python_for_kv/jsfmt.spec.js b/tests/python_for_kv/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_for_kv/jsfmt.spec.js +++ b/tests/python_for_kv/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_hello/__snapshots__/jsfmt.spec.js.snap b/tests/python_hello/__snapshots__/jsfmt.spec.js.snap index f926c5b..ecef354 100644 --- a/tests/python_hello/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_hello/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`hello.py 1`] = ` def hello(x, y): print("hello world", x, y) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def hello(x, y): - print("hello world", x, y) - -`; - -exports[`hello.py 2`] = ` -def hello(x, y): - print("hello world", x, y) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(x, y): print("hello world", x, y) diff --git a/tests/python_hello/jsfmt.spec.js b/tests/python_hello/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_hello/jsfmt.spec.js +++ b/tests/python_hello/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_if/__snapshots__/jsfmt.spec.js.snap b/tests/python_if/__snapshots__/jsfmt.spec.js.snap index 2d367f0..aa9bf70 100644 --- a/tests/python_if/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_if/__snapshots__/jsfmt.spec.js.snap @@ -9,28 +9,7 @@ elif x == 12: print('oh') else: print(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if x == "none": - print("None") -elif x == None: - print("oh") -elif x == 12: - print("oh") -else: - print(123) - -`; - -exports[`if.py 2`] = ` -if x == 'none': - print('None') -elif x == None: - print('oh') -elif x == 12: - print('oh') -else: - print(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if x == "none": print("None") elif x == None: diff --git a/tests/python_if/jsfmt.spec.js b/tests/python_if/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_if/jsfmt.spec.js +++ b/tests/python_if/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_import/__snapshots__/jsfmt.spec.js.snap b/tests/python_import/__snapshots__/jsfmt.spec.js.snap index 5bdfbd3..edb75ba 100644 --- a/tests/python_import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_import/__snapshots__/jsfmt.spec.js.snap @@ -12,34 +12,7 @@ from .models import B as C from .example import * from ..example import * -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -import sys - -from models import X - -from .models import X - -from .models import B as C - -from .example import * - -from ..example import * - -`; - -exports[`import.py 2`] = ` -import sys - -from models import X - -from .models import X - -from .models import B as C - -from .example import * - -from ..example import * -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import sys from models import X diff --git a/tests/python_import/jsfmt.spec.js b/tests/python_import/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_import/jsfmt.spec.js +++ b/tests/python_import/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_kwargs/__snapshots__/jsfmt.spec.js.snap b/tests/python_kwargs/__snapshots__/jsfmt.spec.js.snap index 6be5688..c35aae5 100644 --- a/tests/python_kwargs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_kwargs/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`kwargs.py 1`] = ` def hello(a, **kwargs): print("hello world", a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def hello(a, **kwargs): - print("hello world", a) - -`; - -exports[`kwargs.py 2`] = ` -def hello(a, **kwargs): - print("hello world", a) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def hello(a, **kwargs): print("hello world", a) diff --git a/tests/python_kwargs/jsfmt.spec.js b/tests/python_kwargs/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_kwargs/jsfmt.spec.js +++ b/tests/python_kwargs/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_lambdas/__snapshots__/jsfmt.spec.js.snap b/tests/python_lambdas/__snapshots__/jsfmt.spec.js.snap index 42544b0..a1b85f6 100644 --- a/tests/python_lambdas/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_lambdas/__snapshots__/jsfmt.spec.js.snap @@ -2,16 +2,7 @@ exports[`lambdas.py 1`] = ` key=lambda variable: variable[0] -max(lis, key=lambda x:int(x))~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -key = lambda variable: variable[0] - -max(lis, key=lambda x: int(x)) - -`; - -exports[`lambdas.py 2`] = ` -key=lambda variable: variable[0] -max(lis, key=lambda x:int(x))~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +max(lis, key=lambda x:int(x))~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ key = lambda variable: variable[0] max(lis, key=lambda x: int(x)) diff --git a/tests/python_lambdas/jsfmt.spec.js b/tests/python_lambdas/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_lambdas/jsfmt.spec.js +++ b/tests/python_lambdas/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_list_comp/__snapshots__/jsfmt.spec.js.snap b/tests/python_list_comp/__snapshots__/jsfmt.spec.js.snap index d364338..5d38d5b 100644 --- a/tests/python_list_comp/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_list_comp/__snapshots__/jsfmt.spec.js.snap @@ -3,17 +3,7 @@ exports[`list_comp.py 1`] = ` [x for x in range(100)] [x for x in range(100) if x % 2 == 0] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -[x for x in range(100)] - -[x for x in range(100) if x % 2 == 0] - -`; - -exports[`list_comp.py 2`] = ` -[x for x in range(100)] -[x for x in range(100) if x % 2 == 0] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [x for x in range(100)] [x for x in range(100) if x % 2 == 0] diff --git a/tests/python_list_comp/jsfmt.spec.js b/tests/python_list_comp/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_list_comp/jsfmt.spec.js +++ b/tests/python_list_comp/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_long/__snapshots__/jsfmt.spec.js.snap b/tests/python_long/__snapshots__/jsfmt.spec.js.snap index 424e71e..4afde4c 100644 --- a/tests/python_long/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_long/__snapshots__/jsfmt.spec.js.snap @@ -3,19 +3,7 @@ exports[`hello.py 1`] = ` def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): print("hello world", this_is_another_long_parameter) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def this_is_a_long_function( - this_is_a_long_parameter, - this_is_another_long_parameter -): - print("hello world", this_is_another_long_parameter) - -`; - -exports[`hello.py 2`] = ` -def this_is_a_long_function(this_is_a_long_parameter, this_is_another_long_parameter): - print("hello world", this_is_another_long_parameter) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def this_is_a_long_function( this_is_a_long_parameter, this_is_another_long_parameter diff --git a/tests/python_long/jsfmt.spec.js b/tests/python_long/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_long/jsfmt.spec.js +++ b/tests/python_long/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_nested_if/__snapshots__/jsfmt.spec.js.snap b/tests/python_nested_if/__snapshots__/jsfmt.spec.js.snap index dd29b14..c597798 100644 --- a/tests/python_nested_if/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_nested_if/__snapshots__/jsfmt.spec.js.snap @@ -4,40 +4,17 @@ exports[`nested_if.py 1`] = ` if x == 'none': if False: print('None') -elif x == None: +elif x is None: print('oh') elif x == 12: print('oh') else: print(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if x == "none": if False: print("None") -elif x == None: - print("oh") -elif x == 12: - print("oh") -else: - print(123) - -`; - -exports[`nested_if.py 2`] = ` -if x == 'none': - if False: - print('None') -elif x == None: - print('oh') -elif x == 12: - print('oh') -else: - print(123) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if x == "none": - if False: - print("None") -elif x == None: +elif x is None: print("oh") elif x == 12: print("oh") diff --git a/tests/python_nested_if/jsfmt.spec.js b/tests/python_nested_if/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_nested_if/jsfmt.spec.js +++ b/tests/python_nested_if/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_nested_if/nested_if.py b/tests/python_nested_if/nested_if.py index fd41230..6a6fe85 100644 --- a/tests/python_nested_if/nested_if.py +++ b/tests/python_nested_if/nested_if.py @@ -1,7 +1,7 @@ if x == 'none': if False: print('None') -elif x == None: +elif x is None: print('oh') elif x == 12: print('oh') diff --git a/tests/python_not_in/__snapshots__/jsfmt.spec.js.snap b/tests/python_not_in/__snapshots__/jsfmt.spec.js.snap index 242ebe3..70f3a98 100644 --- a/tests/python_not_in/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_not_in/__snapshots__/jsfmt.spec.js.snap @@ -3,17 +3,7 @@ exports[`not_in.py 1`] = ` a not in x a not in [1, 2] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a not in x - -a not in [1, 2] - -`; - -exports[`not_in.py 2`] = ` -a not in x -a not in [1, 2] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a not in x a not in [1, 2] diff --git a/tests/python_not_in/jsfmt.spec.js b/tests/python_not_in/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_not_in/jsfmt.spec.js +++ b/tests/python_not_in/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_pass/__snapshots__/jsfmt.spec.js.snap b/tests/python_pass/__snapshots__/jsfmt.spec.js.snap index 9867964..8332d03 100644 --- a/tests/python_pass/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_pass/__snapshots__/jsfmt.spec.js.snap @@ -4,22 +4,9 @@ exports[`pass.py 1`] = ` class Client: pass -def x(): pass -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class Client: - pass - def x(): pass - -`; - -exports[`pass.py 2`] = ` -class Client: - pass - -def x(): pass -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Client: pass diff --git a/tests/python_pass/jsfmt.spec.js b/tests/python_pass/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_pass/jsfmt.spec.js +++ b/tests/python_pass/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_pass/pass.py b/tests/python_pass/pass.py index 87de9d7..22a7f2c 100644 --- a/tests/python_pass/pass.py +++ b/tests/python_pass/pass.py @@ -1,4 +1,5 @@ class Client: pass -def x(): pass +def x(): + pass diff --git a/tests/python_return/__snapshots__/jsfmt.spec.js.snap b/tests/python_return/__snapshots__/jsfmt.spec.js.snap index dd76ff9..d972ae9 100644 --- a/tests/python_return/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_return/__snapshots__/jsfmt.spec.js.snap @@ -6,22 +6,7 @@ def example(first): return return first -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def example(first): - if False: - return - - return first - -`; - -exports[`return.py 2`] = ` -def example(first): - if False: - return - - return first -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def example(first): if False: return diff --git a/tests/python_return/jsfmt.spec.js b/tests/python_return/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_return/jsfmt.spec.js +++ b/tests/python_return/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_starred/__snapshots__/jsfmt.spec.js.snap b/tests/python_starred/__snapshots__/jsfmt.spec.js.snap index f5a6a5c..e8723f6 100644 --- a/tests/python_starred/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_starred/__snapshots__/jsfmt.spec.js.snap @@ -2,14 +2,7 @@ exports[`starred.py 1`] = ` func(*args, **kwargs) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -func(*args, **kwargs) - -`; - -exports[`starred.py 2`] = ` -func(*args, **kwargs) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ func(*args, **kwargs) `; diff --git a/tests/python_starred/jsfmt.spec.js b/tests/python_starred/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_starred/jsfmt.spec.js +++ b/tests/python_starred/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_strings/__snapshots__/jsfmt.spec.js.snap b/tests/python_strings/__snapshots__/jsfmt.spec.js.snap index 8757c42..04bf440 100644 --- a/tests/python_strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_strings/__snapshots__/jsfmt.spec.js.snap @@ -6,24 +6,7 @@ a = """this is a multiline string""" b = '''another multiline string''' -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = 'it is "ok"' - -a = """this is a multiline -string""" - -b = """another multiline -string""" - -`; - -exports[`strings.py 2`] = ` -a = "it is \\"ok\\"" -a = """this is a multiline -string""" -b = '''another multiline -string''' -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = 'it is "ok"' a = """this is a multiline diff --git a/tests/python_strings/jsfmt.spec.js b/tests/python_strings/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_strings/jsfmt.spec.js +++ b/tests/python_strings/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_subscript/__snapshots__/jsfmt.spec.js.snap b/tests/python_subscript/__snapshots__/jsfmt.spec.js.snap index 6cc96ab..0f2fff5 100644 --- a/tests/python_subscript/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_subscript/__snapshots__/jsfmt.spec.js.snap @@ -14,44 +14,7 @@ a[::-1] c = {'a': 3} c['a'] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = [1, [2, 2], 3] - -a[0] - -a[0:1] - -a[0:-1] - -a[-1] - -a[0:-1:2] - -a[1][0] - -a[::-1] - -c = {"a": 3} - -c["a"] - -`; - -exports[`subscript.py 2`] = ` -a = [1, [2, 2], 3] - -a[0] -a[0:1] -a[0:-1] -a[-1] -a[0:-1:2] -a[1][0] -a[::-1] - -c = {'a': 3} - -c['a'] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = [1, [2, 2], 3] a[0] diff --git a/tests/python_subscript/jsfmt.spec.js b/tests/python_subscript/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_subscript/jsfmt.spec.js +++ b/tests/python_subscript/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_tagged_strings/__snapshots__/jsfmt.spec.js.snap b/tests/python_tagged_strings/__snapshots__/jsfmt.spec.js.snap index fad0b0a..429f188 100644 --- a/tests/python_tagged_strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_tagged_strings/__snapshots__/jsfmt.spec.js.snap @@ -7,27 +7,7 @@ a = r"""this is a multiline string""" a = u"""this is a multiline string""" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -a = r"it is \\ok" - -a = u"it is ok" - -a = r"""this is a multiline -string""" - -a = u"""this is a multiline -string""" - -`; - -exports[`tagged_strings.py 2`] = ` -a = r"it is \\ok" -a = u"it is ok" -a = r"""this is a multiline -string""" -a = u"""this is a multiline -string""" -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = r"it is \\ok" a = u"it is ok" diff --git a/tests/python_tagged_strings/jsfmt.spec.js b/tests/python_tagged_strings/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_tagged_strings/jsfmt.spec.js +++ b/tests/python_tagged_strings/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_try/__snapshots__/jsfmt.spec.js.snap b/tests/python_try/__snapshots__/jsfmt.spec.js.snap index 5a988ac..95cb6b0 100644 --- a/tests/python_try/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_try/__snapshots__/jsfmt.spec.js.snap @@ -15,44 +15,7 @@ except: raise finally: print("done") -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -try: - f = open("myfile.txt") - - s = f.readline() - - i = int(s.strip()) -except OSError as err: - print("OS error: {0}".format(err)) -except ValueError: - print("Could not convert data to an integer.") - - raise ValueError -except: - print("Unexpected error:") - - raise -finally: - print("done") - -`; - -exports[`try.py 2`] = ` -try: - f = open('myfile.txt') - s = f.readline() - i = int(s.strip()) -except OSError as err: - print("OS error: {0}".format(err)) -except ValueError: - print("Could not convert data to an integer.") - raise ValueError -except: - print("Unexpected error:") - raise -finally: - print("done") -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ try: f = open("myfile.txt") diff --git a/tests/python_try/jsfmt.spec.js b/tests/python_try/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_try/jsfmt.spec.js +++ b/tests/python_try/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_while/__snapshots__/jsfmt.spec.js.snap b/tests/python_while/__snapshots__/jsfmt.spec.js.snap index 830c88d..0261d9c 100644 --- a/tests/python_while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_while/__snapshots__/jsfmt.spec.js.snap @@ -3,16 +3,7 @@ exports[`while.py 1`] = ` while True: print(10) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -while True: - print(10) - -`; - -exports[`while.py 2`] = ` -while True: - print(10) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ while True: print(10) diff --git a/tests/python_while/jsfmt.spec.js b/tests/python_while/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_while/jsfmt.spec.js +++ b/tests/python_while/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests/python_with/__snapshots__/jsfmt.spec.js.snap b/tests/python_with/__snapshots__/jsfmt.spec.js.snap index 4f0fff2..3a6c81f 100644 --- a/tests/python_with/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_with/__snapshots__/jsfmt.spec.js.snap @@ -8,29 +8,7 @@ with open('tmp/index.html'): print('great') with A() as X, B() as Y, C() as Z: - do_something()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -with open("tmp/index.html") as f: - index = f.read() - -with open("tmp/index.html"): - print("great") - -with A() as X: - with B() as Y: - with C() as Z: - do_something() - -`; - -exports[`with.py 2`] = ` -with open('tmp/index.html') as f: - index = f.read() - -with open('tmp/index.html'): - print('great') - -with A() as X, B() as Y, C() as Z: - do_something()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + do_something()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ with open("tmp/index.html") as f: index = f.read() diff --git a/tests/python_with/jsfmt.spec.js b/tests/python_with/jsfmt.spec.js index dc63c4d..147833d 100644 --- a/tests/python_with/jsfmt.spec.js +++ b/tests/python_with/jsfmt.spec.js @@ -1,2 +1 @@ -run_spec(__dirname, ["python"], { pythonVersion: "2" }); -run_spec(__dirname, ["python"], { pythonVersion: "3" }); +run_spec(__dirname, ["python"], "*"); diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 9c3cbe2..58e2181 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -1,16 +1,31 @@ "use strict"; +const spawnSync = require("child_process").spawnSync; const fs = require("fs"); const extname = require("path").extname; const prettier = require("prettier"); const massageAST = require("prettier/src/common/clean-ast").massageAST; +const semver = require("semver"); -const AST_COMPARE = process.env["AST_COMPARE"]; +const PYTHON_VERSION = spawnSync("python", [ + "-c", + "import platform; print(platform.python_version())" +]) + .stdout.toString() + .trim(); + +const AST_COMPARE = process.env.AST_COMPARE; + +function run_spec(dirname, parsers, versionRange, options) { + if (!semver.satisfies(PYTHON_VERSION, versionRange)) { + test.skip(dirname, () => {}); + return; + } -function run_spec(dirname, parsers, options) { options = Object.assign( { plugins: ["."], + printWidth: 79, tabWidth: 4 }, options @@ -36,7 +51,7 @@ function run_spec(dirname, parsers, options) { }); const output = prettyprint(source, path, mergedOptions); test(`${filename} - ${mergedOptions.parser}-verify`, () => { - expect(raw(source + "~".repeat(80) + "\n" + output)).toMatchSnapshot( + expect(raw(source + "~".repeat(79) + "\n" + output)).toMatchSnapshot( filename ); }); @@ -77,6 +92,7 @@ function run_spec(dirname, parsers, options) { } }); } + global.run_spec = run_spec; function stripLocation(ast) { diff --git a/yarn.lock b/yarn.lock index 538788c..32c5739 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2917,7 +2917,7 @@ sax@^1.2.1: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" -"semver@2 || 3 || 4 || 5", semver@5.4.1, semver@^5.1.0, semver@^5.3.0: +"semver@2 || 3 || 4 || 5", semver@5.4.1, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1: version "5.4.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" From 33c98cb84de26a7690e421b6de51d103f3421723 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Tue, 26 Dec 2017 16:58:49 -0800 Subject: [PATCH 04/13] Improve tests --- jest.test.config.js | 1 - tests_config/run_spec.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/jest.test.config.js b/jest.test.config.js index e8d51fa..eab8bce 100644 --- a/jest.test.config.js +++ b/jest.test.config.js @@ -7,7 +7,6 @@ module.exports = { setupFiles: ["/tests_config/run_spec.js"], snapshotSerializers: ["/tests_config/raw-serializer.js"], testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", - testPathIgnorePatterns: ["tests/new_react", "tests/more_react"], collectCoverage: ENABLE_COVERAGE, collectCoverageFrom: ["src/**/*.js", "!/node_modules/"], transform: {} diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 58e2181..57d565b 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -18,7 +18,7 @@ const AST_COMPARE = process.env.AST_COMPARE; function run_spec(dirname, parsers, versionRange, options) { if (!semver.satisfies(PYTHON_VERSION, versionRange)) { - test.skip(dirname, () => {}); + test.skip(dirname); // eslint-disable-line jest/no-disabled-tests return; } From 2e096ff5b5dad0013e752e12ff312a242c53cc22 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 27 Dec 2017 14:16:18 -0800 Subject: [PATCH 05/13] Fix with printing --- src/printer/index.js | 39 ++++++++++++------- .../__snapshots__/jsfmt.spec.js.snap | 5 ++- tests/python_with/with.py | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/printer/index.js b/src/printer/index.js index f15695e..07b746b 100644 --- a/src/printer/index.js +++ b/src/printer/index.js @@ -128,6 +128,29 @@ function printForIn(path, print) { ]); } +function printWith(path, items, print) { + return concat([ + group(concat(["with", line, join(", ", items), ":"])), + indent(concat([hardline, printBody(path, print)])) + ]); +} + +function printPython2With(path, items, print) { + items.push(printWithItem(path, print)); + let result; + + const n = path.getValue(); + if (n.body.length === 1 && n.body[0].ast_type === "With") { + path.each(p => { + result = printPython2With(p, items, print); + }, "body"); + + return result; + } + + return printWith(path, items, print); +} + function printWithItem(path, print) { const parts = [path.call(print, "context_expr")]; @@ -603,19 +626,9 @@ function genericPrint(path, options, print) { } case "With": { - // python 2 and 3 - const items = n.items - ? path.map(print, "items") - : [printWithItem(path, print)]; - - return concat([ - group(concat(["with", line, join(",", items), ":"])), - indent(concat([hardline, printBody(path, print)])) - ]); - } - - case "withitem": { - return printWithItem(path, print); + return n.items + ? printWith(path, path.map(print, "items"), print) // Python 3 + : printPython2With(path, [], print); // Python 2 } case "BoolOp": { diff --git a/tests/python_with/__snapshots__/jsfmt.spec.js.snap b/tests/python_with/__snapshots__/jsfmt.spec.js.snap index 3a6c81f..97fa851 100644 --- a/tests/python_with/__snapshots__/jsfmt.spec.js.snap +++ b/tests/python_with/__snapshots__/jsfmt.spec.js.snap @@ -8,14 +8,15 @@ with open('tmp/index.html'): print('great') with A() as X, B() as Y, C() as Z: - do_something()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + do_something() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ with open("tmp/index.html") as f: index = f.read() with open("tmp/index.html"): print("great") -with A() as X,B() as Y,C() as Z: +with A() as X, B() as Y, C() as Z: do_something() `; diff --git a/tests/python_with/with.py b/tests/python_with/with.py index fd93fea..4f7ac85 100644 --- a/tests/python_with/with.py +++ b/tests/python_with/with.py @@ -5,4 +5,4 @@ print('great') with A() as X, B() as Y, C() as Z: - do_something() \ No newline at end of file + do_something() From ee7d6100c90ba84714a5d069b5fc589b5152c8c7 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 27 Dec 2017 14:22:58 -0800 Subject: [PATCH 06/13] oops --- src/printer/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/printer/index.js b/src/printer/index.js index 07b746b..aa54790 100644 --- a/src/printer/index.js +++ b/src/printer/index.js @@ -631,6 +631,10 @@ function genericPrint(path, options, print) { : printPython2With(path, [], print); // Python 2 } + case "withitem": { + return printWithItem(path, print); + } + case "BoolOp": { return group( join( From 72918859d144f6379a191da6b61bdbed26ec5687 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 27 Dec 2017 14:27:20 -0800 Subject: [PATCH 07/13] Fix caching --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66236c7..6cdfbe9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,11 @@ node_js: - 8 - 9 env: - - PYTHON_VERSION=2.7.11 - - PYTHON_VERSION=3.6.3 + global: + - PYTHON_VERSIONS="2.7.11 3.6.3" + matrix: + - PYTHON_VERSION=2.7.11 + - PYTHON_VERSION=3.6.3 cache: yarn: true directories: @@ -18,8 +21,8 @@ before_install: - curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash - export PATH="/home/travis/.pyenv/bin:$PATH" - eval "$(pyenv init -)" - - pyenv install -s $PYTHON_VERSION + - echo $PYTHON_VERSIONS | xargs -n1 pyenv install -s - pyenv global $PYTHON_VERSION script: - yarn lint - - yarn test -- --runInBand + - yarn test --runInBand From 9691a9c279483ac9bcda510ee14575374712b28a Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Wed, 27 Dec 2017 14:32:31 -0800 Subject: [PATCH 08/13] Fix obsolete snapshot errors --- tests_config/run_spec.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 57d565b..47c216a 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -17,11 +17,6 @@ const PYTHON_VERSION = spawnSync("python", [ const AST_COMPARE = process.env.AST_COMPARE; function run_spec(dirname, parsers, versionRange, options) { - if (!semver.satisfies(PYTHON_VERSION, versionRange)) { - test.skip(dirname); // eslint-disable-line jest/no-disabled-tests - return; - } - options = Object.assign( { plugins: ["."], @@ -44,6 +39,16 @@ function run_spec(dirname, parsers, versionRange, options) { filename[0] !== "." && filename !== "jsfmt.spec.js" ) { + if (!semver.satisfies(PYTHON_VERSION, versionRange)) { + // Skip each test here with the snapshot name below to avoid obsolete + // snapshot failures. + parsers.forEach(() => { + // eslint-disable-next-line jest/no-disabled-tests + test.skip(filename); + }); + return; + } + const source = read(path).replace(/\r\n/g, "\n"); const mergedOptions = Object.assign({}, options, { From ddb74b80d39ab75fa88ef459addeb88c130a895c Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 28 Dec 2017 02:01:21 -0800 Subject: [PATCH 09/13] Fix code --- src/printer/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/printer/index.js b/src/printer/index.js index aa54790..f10e03c 100644 --- a/src/printer/index.js +++ b/src/printer/index.js @@ -137,15 +137,10 @@ function printWith(path, items, print) { function printPython2With(path, items, print) { items.push(printWithItem(path, print)); - let result; const n = path.getValue(); if (n.body.length === 1 && n.body[0].ast_type === "With") { - path.each(p => { - result = printPython2With(p, items, print); - }, "body"); - - return result; + return concat(path.map(p => printPython2With(p, items, print), "body")); } return printWith(path, items, print); From 7a1fdd479b507abe8a0a3fdd3532b08acbfba292 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 28 Dec 2017 02:14:52 -0800 Subject: [PATCH 10/13] Tweak build --- .travis.yml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6cdfbe9..726c212 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,24 +5,17 @@ node_js: - 8 - 9 env: - global: - - PYTHON_VERSIONS="2.7.11 3.6.3" - matrix: - - PYTHON_VERSION=2.7.11 - - PYTHON_VERSION=3.6.3 + - PYTHON_VERSION=2.7.14 + - PYTHON_VERSION=3.6.3 cache: yarn: true directories: - node_modules - - /home/travis/.pyenv -install: - - yarn install before_install: - - curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash - - export PATH="/home/travis/.pyenv/bin:$PATH" - - eval "$(pyenv init -)" - - echo $PYTHON_VERSIONS | xargs -n1 pyenv install -s - pyenv global $PYTHON_VERSION + - python --version +install: + - yarn install script: - yarn lint - yarn test --runInBand From b1f31a06653884378ecb246b8910d320322d8805 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 28 Dec 2017 02:17:26 -0800 Subject: [PATCH 11/13] Install first just in case --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 726c212..08406ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ cache: directories: - node_modules before_install: + - pyenv install -s $PYTHON_VERSION - pyenv global $PYTHON_VERSION - python --version install: From 3c47843257c377c630ad166bc70a4518655324f6 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 28 Dec 2017 12:08:35 -0800 Subject: [PATCH 12/13] Use printWidth --- tests_config/run_spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 47c216a..4e468fb 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -56,9 +56,9 @@ function run_spec(dirname, parsers, versionRange, options) { }); const output = prettyprint(source, path, mergedOptions); test(`${filename} - ${mergedOptions.parser}-verify`, () => { - expect(raw(source + "~".repeat(79) + "\n" + output)).toMatchSnapshot( - filename - ); + expect( + raw(source + "~".repeat(mergedOptions.printWidth) + "\n" + output) + ).toMatchSnapshot(filename); }); parsers.slice(1).forEach(parserName => { From 4a0c38d2cdb79fc3868c31d94f7a288652559673 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Sat, 30 Dec 2017 17:32:07 -0800 Subject: [PATCH 13/13] Clarify comment --- tests_config/run_spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 4e468fb..c384561 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -40,8 +40,9 @@ function run_spec(dirname, parsers, versionRange, options) { filename !== "jsfmt.spec.js" ) { if (!semver.satisfies(PYTHON_VERSION, versionRange)) { - // Skip each test here with the snapshot name below to avoid obsolete - // snapshot failures. + // We need to explicitly skip tests that are disabled for the current + // version of Python, using the same name as the snapshot name below. + // Otherwise we get obsolete snapshot failures for these tests. parsers.forEach(() => { // eslint-disable-next-line jest/no-disabled-tests test.skip(filename);