Ejemplo n.º 1
0
 def test_parse_options_none(self):
     """Test when option is not defined or has a default value of None."""
     options = mock.Mock(spec=())
     options.author_re = None
     Checker.parse_options(options)
     self.assertEqual(0, len(Checker.author_re))
     self.assertEqual(0, len(Checker.copyright_re))
     self.assertEqual(0, len(Checker.license_re))
Ejemplo n.º 2
0
 def test_parse_options(self):
     """Test :meth:`flake8_ownership.Checker.parse_options`."""
     options = mock.Mock()
     options.author_re = ''
     options.copyright_re = 'item 1'
     options.license_re = 'item 2, item 3'
     Checker.parse_options(options)
     self.assertEqual(0, len(Checker.author_re))
     self.assertEqual(1, len(Checker.copyright_re))
     self.assertEqual(2, len(Checker.license_re))
Ejemplo n.º 3
0
 def test_add_options(self):
     """Test :meth:`flake8_ownership.Checker.add_options`."""
     expected_calls = []
     for tag in ('author', 'copyright', 'license'):
         expected_calls.append(mock.call(
             '--%s-re' % tag,
             help='regular expression(s) for valid :%s: lines' % tag,
             parse_from_config=True,
         ))
     parser = mock.Mock()
     Checker.add_options(parser)
     parser.add_option.assert_has_calls(expected_calls, any_order=True)
Ejemplo n.º 4
0
    def check(self):
        """
        Run checker on the temporary file (call after :meth:`write`).

        :return: List of errors from the checker. Each error is of the format
                 ``(line<int>, column<int>, message<str>, klass<type>)``.
        :rtype: :class:`list`
        """
        self._tmp.flush()
        self._tmp.close()
        return list(Checker(None, self._tmp_path).run())
Ejemplo n.º 5
0
    def test_parse_option(self):
        """Test :meth:`flake8_ownership.Checker._parse_option`."""
        options = mock.Mock()
        options.test = 'item 1, item 2<COMMA> <YEAR>'
        regexes = Checker._parse_option(options, 'test')
        self.assertEqual(2, len(regexes))
        r1, r2 = regexes

        r1string, r1regex = r1
        self.assertEqual('item 1', r1string)
        self.assertTrue(type(r1regex) is type(re.compile('')))  # noqa: E721

        r2string, r2regex = r2
        r2string_expected = 'item 2, %s' % datetime.datetime.today().year
        self.assertEqual(r2string_expected, r2string)
        self.assertTrue(type(r2regex) is type(re.compile('')))  # noqa: E721