Skip to content

Commit 225ca2b

Browse files
authored
Add test coverage: normalizeForInterpreter.py (microsoft#4680)
* Add Copyright/license header to testing_tools * Add some tests against the pythonFiles
1 parent 0c581b2 commit 225ca2b

10 files changed

Lines changed: 118 additions & 0 deletions

File tree

pythonFiles/tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.

pythonFiles/tests/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
import os.path
25
import sys
36

pythonFiles/tests/run_all.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
# Replace the "." entry.
25
import os.path
36
import sys
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import pytest
5+
import textwrap
6+
7+
import normalizeForInterpreter
8+
9+
10+
class TestNormalizationScript(object):
11+
"""Basic unit tests for the normalization script."""
12+
13+
def test_basicNormalization(self, capsys):
14+
src = 'print("this is a test")'
15+
normalizeForInterpreter.normalize_lines(src)
16+
captured = capsys.readouterr()
17+
assert captured.out == src
18+
19+
def test_moreThanOneLine(self, capsys):
20+
src = textwrap.dedent("""\
21+
# Some rando comment
22+
23+
def show_something():
24+
print("Something")
25+
"""
26+
)
27+
normalizeForInterpreter.normalize_lines(src)
28+
captured = capsys.readouterr()
29+
assert captured.out == src
30+
31+
def test_withHangingIndent(self, capsys):
32+
src = textwrap.dedent("""\
33+
x = 22
34+
y = 30
35+
z = -10
36+
result = x + y + z
37+
38+
if result == 42:
39+
print("The answer to life, the universe, and everything")
40+
"""
41+
)
42+
normalizeForInterpreter.normalize_lines(src)
43+
captured = capsys.readouterr()
44+
assert captured.out == src
45+
46+
def test_clearOutExtraneousNewlines(self, capsys):
47+
src = textwrap.dedent("""\
48+
value_x = 22
49+
50+
value_y = 30
51+
52+
value_z = -10
53+
54+
print(value_x + value_y + value_z)
55+
56+
"""
57+
)
58+
expectedResult = textwrap.dedent("""\
59+
value_x = 22
60+
value_y = 30
61+
value_z = -10
62+
print(value_x + value_y + value_z)
63+
64+
"""
65+
)
66+
normalizeForInterpreter.normalize_lines(src)
67+
result = capsys.readouterr()
68+
assert result.out == expectedResult
69+
70+
def test_clearOutExtraLinesAndWhitespace(self, capsys):
71+
src = textwrap.dedent("""\
72+
if True:
73+
x = 22
74+
75+
y = 30
76+
77+
z = -10
78+
79+
print(x + y + z)
80+
81+
"""
82+
)
83+
expectedResult = textwrap.dedent("""\
84+
if True:
85+
x = 22
86+
y = 30
87+
z = -10
88+
89+
print(x + y + z)
90+
91+
"""
92+
)
93+
normalizeForInterpreter.normalize_lines(src)
94+
result = capsys.readouterr()
95+
assert result.out == expectedResult
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.

pythonFiles/tests/testing_tools/adapter/test___main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
import unittest
25

36
from ...util import Stub, StubProxy

pythonFiles/tests/testing_tools/adapter/test_pytest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
import os.path
25
import unittest
36

pythonFiles/tests/testing_tools/adapter/test_report.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
import json
25
import os.path
36
import unittest

pythonFiles/tests/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
13

24
class Stub(object):
35

0 commit comments

Comments
 (0)