Skip to content

Commit

Permalink
Update tests (no skip, more tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimadeline committed Oct 20, 2020
1 parent 047de5e commit c2b567e
Showing 1 changed file with 84 additions and 27 deletions.
111 changes: 84 additions & 27 deletions pythonFiles/tests/test_normalize_for_interpreter.py
@@ -1,30 +1,20 @@
# 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."""
"""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")'
expected = src + "\n\n"
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == src
assert captured.out == expected

@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(
"""\
Expand All @@ -34,14 +24,17 @@ def show_something():
print("Something")
"""
)
expected = textwrap.dedent(
"""\
def show_something():
print("Something")
"""
)
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == src
assert captured.out == expected

@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(
"""\
Expand All @@ -54,14 +47,25 @@ def test_withHangingIndent(self, capsys):
print("The answer to life, the universe, and everything")
"""
)
expected = 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
assert captured.out == expected

@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(
"""\
Expand All @@ -78,8 +82,11 @@ def test_clearOutExtraneousNewlines(self, capsys):
expectedResult = textwrap.dedent(
"""\
value_x = 22
value_y = 30
value_z = -10
print(value_x + value_y + value_z)
"""
Expand All @@ -88,10 +95,6 @@ def test_clearOutExtraneousNewlines(self, capsys):
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(
"""\
Expand Down Expand Up @@ -120,3 +123,57 @@ def test_clearOutExtraLinesAndWhitespace(self, capsys):
normalizeForInterpreter.normalize_lines(src)
result = capsys.readouterr()
assert result.out == expectedResult

def test_partialSingleLine(self, capsys):
src = " print('foo')"
expected = textwrap.dedent(src) + "\n\n"
normalizeForInterpreter.normalize_lines(src)
result = capsys.readouterr()
assert result.out == expected

def test_multiLineWithIndent(self, capsys):
src = """\
if (x > 0
and condition == True):
print('foo')
else:
print('bar')
"""

expectedResult = textwrap.dedent(
"""\
if (x > 0
and condition == True):
print('foo')
else:
print('bar')
"""
)

normalizeForInterpreter.normalize_lines(src)
result = capsys.readouterr()
assert result.out == expectedResult

def test_multiLineWithComment(self, capsys):
src = textwrap.dedent(
"""\
def show_something():
# Some rando comment
print("Something")
"""
)
expected = textwrap.dedent(
"""\
def show_something():
# Some rando comment
print("Something")
"""
)
normalizeForInterpreter.normalize_lines(src)
captured = capsys.readouterr()
assert captured.out == expected

0 comments on commit c2b567e

Please sign in to comment.