Ai
1 Star 0 Fork 0

joyni/vscode-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_normalize_for_interpreter.py 3.12 KB
一键复制 编辑 原始数据 按行查看 历史
Kim-Adeline Miguel 提交于 2020-01-25 02:05 +08:00 . Format Python files with Black (#9742)
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import pytest
import sys
import textwrap
import normalizeForInterpreter
class TestNormalizationScript(object):
"""Basic unit tests for the normalization script."""
@pytest.mark.skipif(
sys.version_info.major == 2,
reason="normalizeForInterpreter not working for 2.7, see GH #4805",
)
def test_basicNormalization(self, capsys):
src = 'print("this is a test")'
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == src
@pytest.mark.skipif(
sys.version_info.major == 2,
reason="normalizeForInterpreter not working for 2.7, see GH #4805",
)
def test_moreThanOneLine(self, capsys):
src = textwrap.dedent(
"""\
# Some rando comment
def show_something():
print("Something")
"""
)
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == src
@pytest.mark.skipif(
sys.version_info.major == 2,
reason="normalizeForInterpreter not working for 2.7, see GH #4805",
)
def test_withHangingIndent(self, capsys):
src = textwrap.dedent(
"""\
x = 22
y = 30
z = -10
result = x + y + z
if result == 42:
print("The answer to life, the universe, and everything")
"""
)
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == src
@pytest.mark.skipif(
sys.version_info.major == 2,
reason="normalizeForInterpreter not working for 2.7, see GH #4805",
)
def test_clearOutExtraneousNewlines(self, capsys):
src = textwrap.dedent(
"""\
value_x = 22
value_y = 30
value_z = -10
print(value_x + value_y + value_z)
"""
)
expectedResult = textwrap.dedent(
"""\
value_x = 22
value_y = 30
value_z = -10
print(value_x + value_y + value_z)
"""
)
normalizeForInterpreter.normalize_lines(src)
result = capsys.readouterr()
assert result.out == expectedResult
@pytest.mark.skipif(
sys.version_info.major == 2,
reason="normalizeForInterpreter not working for 2.7, see GH #4805",
)
def test_clearOutExtraLinesAndWhitespace(self, capsys):
src = textwrap.dedent(
"""\
if True:
x = 22
y = 30
z = -10
print(x + y + z)
"""
)
expectedResult = textwrap.dedent(
"""\
if True:
x = 22
y = 30
z = -10
print(x + y + z)
"""
)
normalizeForInterpreter.normalize_lines(src)
result = capsys.readouterr()
assert result.out == expectedResult
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/luluunusually/vscode-python.git
git@gitee.com:luluunusually/vscode-python.git
luluunusually
vscode-python
vscode-python
master

搜索帮助