Esempio n. 1
0
    def test_config_on(self):
        '''Check for newlines around a block including comments.'''
        config.reset()
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\

            thing = 8
            |start|

            #


            if False:
                pass
                |cursor|
            else:
                # info here
                # and there


                print('asdds')

            |end|
            # asdfasdf


            print('asdf')
            '''
        )

        self.compare(code, two_way=True, extra_lines=True)
Esempio n. 2
0
    def test_config_off(self):
        '''Get only the block.'''
        config.reset()
        config.register_setting(config.COMMENT_KEY, lambda: False)
        config.register_setting(config.WHITESPACE_KEY, lambda: False)

        code = textwrap.dedent(
            '''\

            thing = 8


            #


            |start|if False:
                pass
                |cursor|
            else:
                # info here
                # and there


                print('asdds')|end|

            # asdfasdf



            print('asdf')
            '''
        )

        self.compare(code, two_way=True, extra_lines=False)
Esempio n. 3
0
    def test_strict_search_002(self):
        '''Find source-code which is only defined at the block's definition.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: False)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\

            whatever = 'asdfafsd'

            # some comment
            # more
            #
            another = 'asdf'
            |start|


            try:
                pass
            except ValueError:
                another = 'ttt'
                pass|cursor|
            else:
                pass
            |end|
            lastly = 'done'
            '''
        )

        self.compare(code, two_way=True, extra_lines=False, search=True)
Esempio n. 4
0
    def test_strict_search_001b(self):
        '''Find source-code which is only defined at the block's definition.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: False)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\

            whatever = 'asdfafsd'

            |start|# some comment
            # more
            #

            another = ['asdf', 'ttt']

            for index, item in enumerate(another):
                whatever = item

                # more lines|cursor|

                print('still going')
            |end|
            lastly = 'done'
            '''
        )

        self.compare(code, two_way=True, extra_lines=False, search=True)
Esempio n. 5
0
    def test_if_python_node(self):
        '''Test so that callable objects in Python still "find" identifiers correctly.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: False)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\
            stuff = 10


            |start|# asdfasdf
            #asdfsdf
            #
            another = 8

            if hasattr(another, 'foo'):
                pass
            else:
                |cursor|
                thing = 0
                print('asdfsd')

            |end|
            more_items = True
            '''
        )

        self.compare(code, extra_lines=False, two_way=True, search=True)
    def test_no_source_or_previous_node(self):
        '''Find source-code which is defined within the Python block.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: True)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\

            |start|# some comment
            # more
            #

            for item in another:
                whatever = item
                |cursor|
                # more lines

                print('still going')
            |end|
            lastly = 'done'
            '''
        )

        self.compare(code, two_way=True, extra_lines=False, search=True)
Esempio n. 7
0
    def test_case_002(self):
        '''Test that block_party does not grab the entire Python function.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: True)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\
            def main():
                import argparse

                tttttt.asdfasdsdf(yyyyyyy)
                |start|whatever = 8

                while True:
                    whatever = 'asdfsfd'



                    # info here
                    # another bit
                    |cursor|items = 'asdfsd'
                    aaaaa = 'tt'

                    for foo in items:

                        # whatever,
                        asdfsa

                        if True:
                            # pasdfasfd

                            pass
                            # asdfafd
                        elif ting:
                            pass

                        # asdfasdf

                    else:
                        thing


                    # asdfadsffdasd
                    # asdfsdfkk,w
                    more = 'asdf'

                |end|
                #asdfasdf
                argparse.ArgumentParser()
            '''
        )

        self.compare(code, two_way=True, search=True)
    def test_previous_node(self):
        '''Find source-code which is defined within the Python block.'''
        config.register_setting(config.WHITESPACE_KEY, lambda: False)

        code = textwrap.dedent(
            '''\

            |start|if False:

                pass
                |cursor|
                # 'asdfasfdasdf'
            else:
                print('asfasdf')|end|

            '''
        )

        self.compare(code, search=False)
    def test_greedy_search(self):
        '''Find source-code which is defined within the Python block.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.GREEDY_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent('''\

            |start|# some comment
            # more
            #

            whatever = 'asdfafsd'
            another = ['asdf', 'ttt']

            for item in another:
                whatever = item

                # more lines|cursor|

                print('still going')
            |end|
            lastly = 'done'
            ''')

        self.compare(code, two_way=True, extra_lines=False, search=True)
    def test_search_whitespace(self):
        '''Run a test with searching and whitespace allowed.'''
        config.register_setting(config.WHITESPACE_KEY, lambda: True)
        config.register_setting(config.SEARCH_KEY, lambda: False)

        code = textwrap.dedent('''\
            items = [x for x in whatever]
            |start|


            for index in items:

                print('running')

                # foobar

                |cursor|
                print('index {}'.format(index))|end|

            last = 'bit is here'
            ''')

        self.compare(code, search=True)
Esempio n. 11
0
    def test_case_001(self):
        '''Test that block_party does not grab the entire Python function.'''
        config.register_setting(config.COMMENT_KEY, lambda: True)
        config.register_setting(config.SEARCH_KEY, lambda: True)
        config.register_setting(config.WHITESPACE_KEY, lambda: True)

        code = textwrap.dedent(
            '''\
            def main():
                import argparse

                asdfadsf

                while True:
                    foobar = 8
                    # more docs

                    |start|# asdfasdfasdf
                    # asdfasdfdfsdfsdfa as asf dsd f  fd
                    items = 'asdfsd'



                    for asdfsdf in items:

                        # whatever,
                        asdfsa

                        |cursor|

                        if True:
                            # pasdfasfd

                            pass
                            # asdfafd
                        elif ting:
                            pass
                    else:
                        thing|end|

                    # asdfadsffdasd
                    # asdfsdfkk,w
                    more = 'asdf'

                argparse.ArgumentParser()
            '''
        )

        self.compare(code, search=True)
Esempio n. 12
0
 def setUp(self):
     '''Reset the configuration to some reasonable default settings.'''
     super(BlocksExtraLinesOn, self).setUp()
     config.reset()
     config.register_setting(config.COMMENT_KEY, lambda: False)
     config.register_setting(config.WHITESPACE_KEY, lambda: False)
Esempio n. 13
0
 def setUpClass(cls):
     '''Change the user's settings to include comments.'''
     super(Blocks, cls).setUpClass()
     config.register_setting(config.COMMENT_KEY, lambda: True)
     config.register_setting(config.WHITESPACE_KEY, lambda: False)
Esempio n. 14
0
 def setUpClass(cls):
     '''Allow whitespace during the initial search.'''
     super(BlockWhitespace, cls).setUpClass()
     config.register_setting(config.WHITESPACE_KEY, lambda: True)