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')
        
        """
        )

        normalizeSelection.normalize_lines(src)
        result = capsys.readouterr()
        assert result.out == expectedResult
    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")
            """
        )
        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")
            
            """
        )
        normalizeSelection.normalize_lines(src)
        captured = capsys.readouterr()
        assert captured.out == expected
    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)
            """
        )
        normalizeSelection.normalize_lines(src)
        result = capsys.readouterr()
        assert result.out == expectedResult
    def test_multilineException(self, capsys):
        src = textwrap.dedent(
            """\

            def show_something():
                if True:
            """
        )
        expected = src + "\n\n"
        normalizeSelection.normalize_lines(src)
        captured = capsys.readouterr()
        assert captured.out == expected
    def test_withHangingIndent(self):
        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")
            """
        )
        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")
            
            """
        )
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
    def test_clearOutExtraLinesAndWhitespace(self):
        src = textwrap.dedent(
            """\
            if True:
                x = 22

                y = 30

                z = -10

            print(x + y + z)

            """
        )
        expected = textwrap.dedent(
            """\
            if True:
                x = 22
                y = 30
                z = -10

            print(x + y + z)
            """
        )
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
Пример #7
0
    def test_decorators(self):
        src = textwrap.dedent("""\
            def foo(func):

                def wrapper():
                    print('before')
                    func()
                    print('after')

                return wrapper


            @foo
            def show_something():
                print("Something")
            """)
        expected = textwrap.dedent("""\
            def foo(func):
                def wrapper():
                    print('before')
                    func()
                    print('after')
                return wrapper

            @foo
            def show_something():
                print("Something")

            """)
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
Пример #8
0
    def test_multilineException(self):
        src = textwrap.dedent("""\

            def show_something():
                if True:
            """)
        expected = src + "\n\n"
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
    def test_moreThanOneLine(self, capsys):
        src = textwrap.dedent(
            """\
            # Some rando comment

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

            def show_something():
                # A comment
                print("Something")
            """
        )
        expected = textwrap.dedent(
            """\
            def show_something():
                # A comment
                print("Something")
            
            """
        )
        normalizeSelection.normalize_lines(src)
        captured = capsys.readouterr()
        assert captured.out == expected
Пример #11
0
    def test_moreThanOneLine(self):
        src = textwrap.dedent("""\
            # Some rando comment

            def show_something():
                print("Something")
            """)
        expected = textwrap.dedent("""\
            def show_something():
                print("Something")

            """)
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
    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)
            """
        )
        normalizeSelection.normalize_lines(src)
        result = capsys.readouterr()
        assert result.out == expectedResult
Пример #13
0
    def test_multiLineWithComment(self):
        src = textwrap.dedent("""\

            def show_something():
                # A comment
                print("Something")
            """)
        expected = textwrap.dedent("""\
            def show_something():
                # A comment
                print("Something")

            """)
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
Пример #14
0
    def test_clearOutExtraneousNewlines(self):
        src = textwrap.dedent("""\
            value_x = 22

            value_y = 30

            value_z = -10

            print(value_x + value_y + value_z)

            """)
        expected = textwrap.dedent("""\
            value_x = 22
            value_y = 30
            value_z = -10
            print(value_x + value_y + value_z)
            """)
        result = normalizeSelection.normalize_lines(src)
        assert result == expected
Пример #15
0
    def test_multiLineWithIndent(self):
        src = """\

        if (x > 0
            and condition == True):
            print('foo')
        else:

            print('bar')
        """

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

        """)

        result = normalizeSelection.normalize_lines(src)
        assert result == expected
Пример #16
0
 def test_partialSingleLine(self):
     src = "   print('foo')"
     expected = textwrap.dedent(src) + "\n"
     result = normalizeSelection.normalize_lines(src)
     assert result == expected
Пример #17
0
 def test_basicNormalization(self):
     src = 'print("this is a test")'
     expected = src + "\n"
     result = normalizeSelection.normalize_lines(src)
     assert result == expected
 def test_exception(self, capsys):
     src = "       if True:"
     expected = src + "\n\n"
     normalizeSelection.normalize_lines(src)
     captured = capsys.readouterr()
     assert captured.out == expected
 def test_partialSingleLine(self, capsys):
     src = "   print('foo')"
     expected = textwrap.dedent(src) + "\n"
     normalizeSelection.normalize_lines(src)
     result = capsys.readouterr()
     assert result.out == expected
 def test_basicNormalization(self, capsys):
     src = 'print("this is a test")'
     expected = src + "\n"
     normalizeSelection.normalize_lines(src)
     captured = capsys.readouterr()
     assert captured.out == expected
Пример #21
0
 def test_exception(self):
     src = "       if True:"
     expected = src + "\n\n"
     result = normalizeSelection.normalize_lines(src)
     assert result == expected