Beispiel #1
0
class SpaceConsistencyBearTest(LocalBearTestHelper):

    def setUp(self):
        self.section = Section("test section")
        self.uut = SpaceConsistencyBear(self.section, Queue())

    def test_needed_settings(self):
        self.section.append(Setting("use_spaces", "true"))

        needed_settings = self.uut.get_non_optional_settings()
        self.assertEqual(len(needed_settings),
                         1 + len(SpacingHelper.get_non_optional_settings()))
        self.assertIn("use_spaces", needed_settings)

    def test_defaults(self):
        # use_spaces is no default, need to set it explicitly.
        self.section.append(Setting("use_spaces", "true"))

        self.assertLineValid(self.uut, "    t")
        self.assertLineInvalid(self.uut, "\tt")
        self.assertLineInvalid(self.uut, "t \n")
        self.assertLineInvalid(self.uut, "t", prepare_lines=False)

    def test_data_sets_spaces(self):
        self.section.append(Setting("use_spaces", "true"))
        self.section.append(Setting("allow_trailing_whitespace", "false"))
        self.section.append(Setting("enforce_newline_at_EOF", "false"))

        self.assertLineValid(self.uut, "    t")
        self.assertLineInvalid(self.uut, "t \n")
        self.assertLineInvalid(self.uut, "\tt\n")

    def test_data_sets_tabs(self):
        self.section.append(Setting("use_spaces", "false"))
        self.section.append(Setting("allow_trailing_whitespace", "true"))
        self.section.append(Setting("enforce_newline_at_EOF", "false"))

        self.assertLineInvalid(self.uut, "    t")
        self.assertLineValid(self.uut, "t \n")
        self.assertLineValid(self.uut, "\tt\n")

    def test_enforce_newline_at_eof(self):
        self.section.append(Setting("use_spaces", "true"))
        self.section.append(Setting("allow_trailing_whitespace", "true"))
        self.section.append(Setting("enforce_newline_at_EOF", "true"))

        self.assertLineValid(self.uut, "hello world  \n", prepare_lines=False)
        self.assertLinesValid(self.uut,
                              ["def somecode():\n",
                               "    print('funny')\n",
                               "    print('funny end.')\n"],
                              prepare_lines=False)
        self.assertLineInvalid(self.uut,
                               " no hello world",
                               prepare_lines=False)
        self.assertLinesInvalid(self.uut,
                                ["def unfunny_code():\n",
                                 "    print('funny')\n",
                                 "    print('the result is not funny...')"],
                                prepare_lines=False)
class SpaceConsistencyBearTest(LocalBearTestHelper):
    def setUp(self):
        self.section = Section('test section')
        self.uut = SpaceConsistencyBear(self.section, Queue())

    def test_needed_settings(self):
        self.section.append(Setting('use_spaces', 'true'))

        needed_settings = self.uut.get_non_optional_settings()
        self.assertEqual(len(needed_settings),
                         1 + len(SpacingHelper.get_non_optional_settings()))
        self.assertIn('use_spaces', needed_settings)

    def test_defaults(self):
        # use_spaces is no default, need to set it explicitly.
        self.section.append(Setting('use_spaces', 'true'))

        self.check_validity(self.uut, ['    t'])
        self.check_invalidity(self.uut, ['\tt'])
        self.check_invalidity(self.uut, ['t \n'])
        self.check_invalidity(self.uut, ['t'], force_linebreaks=False)

    def test_data_sets_spaces(self):
        self.section.append(Setting('use_spaces', 'true'))
        self.section.append(Setting('allow_trailing_whitespace', 'false'))
        self.section.append(Setting('enforce_newline_at_EOF', 'false'))

        self.check_validity(self.uut, ['    t'])
        self.check_invalidity(self.uut, ['t \n'])
        self.check_invalidity(self.uut, ['\tt\n'])

    def test_data_sets_tabs(self):
        self.section.append(Setting('use_spaces', 'false'))
        self.section.append(Setting('allow_trailing_whitespace', 'true'))
        self.section.append(Setting('enforce_newline_at_EOF', 'false'))

        self.check_invalidity(self.uut, ['    t'])
        self.check_validity(self.uut, ['t \n'])
        self.check_validity(self.uut, ['\tt\n'])

    def test_enforce_newline_at_eof(self):
        self.section.append(Setting('use_spaces', 'true'))
        self.section.append(Setting('allow_trailing_whitespace', 'true'))
        self.section.append(Setting('enforce_newline_at_EOF', 'true'))

        self.check_validity(self.uut, ['hello world  \n'],
                            force_linebreaks=False)
        self.check_validity(self.uut, [
            'def somecode():\n', "    print('funny')\n",
            "    print('funny end.')\n"
        ],
                            force_linebreaks=False)
        self.check_invalidity(self.uut, [' no hello world'],
                              force_linebreaks=False)
        self.check_invalidity(self.uut, [
            'def unfunny_code():\n', "    print('funny')\n",
            "    print('the result is not funny...')"
        ],
                              force_linebreaks=False)
class SpaceConsistencyBearTest(LocalBearTestHelper):
    def setUp(self):
        self.section = Section("test section")
        self.uut = SpaceConsistencyBear(self.section, Queue())

    def test_needed_settings(self):
        self.section.append(Setting("use_spaces", "true"))

        needed_settings = self.uut.get_non_optional_settings()
        self.assertEqual(len(needed_settings),
                         1 + len(SpacingHelper.get_non_optional_settings()))
        self.assertIn("use_spaces", needed_settings)

    def test_defaults(self):
        # use_spaces is no default, need to set it explicitly.
        self.section.append(Setting("use_spaces", "true"))

        self.assertLineValid(self.uut, "    t")
        self.assertLineInvalid(self.uut, "\tt")
        self.assertLineInvalid(self.uut, "t \n")
        self.assertLineInvalid(self.uut, "t", prepare_lines=False)

    def test_data_sets_spaces(self):
        self.section.append(Setting("use_spaces", "true"))
        self.section.append(Setting("allow_trailing_whitespace", "false"))
        self.section.append(Setting("enforce_newline_at_EOF", "false"))

        self.assertLineValid(self.uut, "    t")
        self.assertLineInvalid(self.uut, "t \n")
        self.assertLineInvalid(self.uut, "\tt\n")

    def test_data_sets_tabs(self):
        self.section.append(Setting("use_spaces", "false"))
        self.section.append(Setting("allow_trailing_whitespace", "true"))
        self.section.append(Setting("enforce_newline_at_EOF", "false"))

        self.assertLineInvalid(self.uut, "    t")
        self.assertLineValid(self.uut, "t \n")
        self.assertLineValid(self.uut, "\tt\n")

    def test_enforce_newline_at_eof(self):
        self.section.append(Setting("use_spaces", "true"))
        self.section.append(Setting("allow_trailing_whitespace", "true"))
        self.section.append(Setting("enforce_newline_at_EOF", "true"))

        self.assertLineValid(self.uut, "hello world  \n", prepare_lines=False)
        self.assertLinesValid(self.uut,
                              ["def somecode():\n",
                               "    print('funny')\n",
                               "    print('funny end.')\n"],
                              prepare_lines=False)
        self.assertLineInvalid(self.uut,
                               " no hello world",
                               prepare_lines=False)
        self.assertLinesInvalid(self.uut,
                                ["def unfunny_code():\n",
                                 "    print('funny')\n",
                                 "    print('the result is not funny...')"],
                                prepare_lines=False)
class SpaceConsistencyBearTest(LocalBearTestHelper):

    def setUp(self):
        self.section = Section('test section')
        self.uut = SpaceConsistencyBear(self.section, Queue())

    def test_needed_settings(self):
        self.section.append(Setting('use_spaces', 'true'))

        needed_settings = self.uut.get_non_optional_settings()
        self.assertEqual(len(needed_settings),
                         1 + len(SpacingHelper.get_non_optional_settings()))
        self.assertIn('use_spaces', needed_settings)

    def test_defaults(self):
        # use_spaces is no default, need to set it explicitly.
        self.section.append(Setting('use_spaces', 'true'))

        self.check_validity(self.uut, ['    t'])
        self.check_validity(self.uut, ['\tt'], valid=False)
        self.check_validity(self.uut, ['t \n'], valid=False)
        self.check_validity(self.uut, ['t'],
                            force_linebreaks=False, valid=False)

    def test_data_sets_spaces(self):
        self.section.append(Setting('use_spaces', 'true'))
        self.section.append(Setting('allow_trailing_whitespace', 'false'))
        self.section.append(Setting('enforce_newline_at_EOF', 'false'))

        self.check_validity(self.uut, ['    t'])
        self.check_validity(self.uut, ['t \n'], valid=False)
        self.check_validity(self.uut, ['\tt\n'], valid=False)

    def test_data_sets_tabs(self):
        self.section.append(Setting('use_spaces', 'false'))
        self.section.append(Setting('allow_trailing_whitespace', 'true'))
        self.section.append(Setting('enforce_newline_at_EOF', 'false'))

        self.check_validity(self.uut, ['    t'], valid=False)
        self.check_validity(self.uut, ['t \n'])
        self.check_validity(self.uut, ['\tt\n'])

    def test_enforce_newline_at_eof(self):
        self.section.append(Setting('use_spaces', 'true'))
        self.section.append(Setting('allow_trailing_whitespace', 'true'))
        self.section.append(Setting('enforce_newline_at_EOF', 'true'))

        self.check_validity(self.uut,
                            ['hello world  \n'],
                            force_linebreaks=False)
        self.check_validity(self.uut,
                            ['def somecode():\n',
                             "    print('funny')\n",
                             "    print('funny end.')\n"],
                            force_linebreaks=False)
        self.check_validity(self.uut,
                            [' no hello world'],
                            force_linebreaks=False,
                            valid=False)
        self.check_validity(self.uut,
                            ['def unfunny_code():\n',
                             "    print('funny')\n",
                             "    print('the result is not funny...')"],
                            force_linebreaks=False,
                            valid=False)
 def setUp(self):
     self.section = Section('test section')
     self.uut = SpaceConsistencyBear(self.section, Queue())
Beispiel #6
0
 def setUp(self):
     self.section = Section("test section")
     self.uut = SpaceConsistencyBear(self.section, Queue())