Browse Source

Fixed errors in tests

master
Rafal Lalik 5 years ago
committed by Johann Schmitz
parent
commit
2914315c36
Signed by: ercpe GPG Key ID: A084064277C501ED
  1. 4
      Makefile
  2. 4
      src/gitbrowser/utils/linking.py
  3. 21
      src/gitbrowser/utils/perlcrap.py
  4. 10
      tests/test_perlcrap.py

4
Makefile

@ -1,9 +1,11 @@
TARGET?=tests
test:
@python --version
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=".:src" django-admin.py test ${TARGET} -v2
coverage:
@python --version
coverage erase
PYTHONPATH="." coverage run --source='src' src/manage.py test tests --settings "tests.settings"
coverage report
coverage report

4
src/gitbrowser/utils/linking.py

@ -3,11 +3,11 @@ import re
from django.core.urlresolvers import reverse
from django.utils.html import format_html, escape
from gitdb.exc import BadName
from six import u
class Autolinker(object):
# http://daringfireball.net/2010/07/improved_regex_for_matching_urls
GRUBER_URLINTEXT_PAT = re.compile(ur"""(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""")
GRUBER_URLINTEXT_PAT = re.compile(u(r"""(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))"""))
def link(self, raw_text, repository):
message = escape(raw_text)

21
src/gitbrowser/utils/perlcrap.py

@ -55,12 +55,11 @@ class DataDumperReader(object):
Primitives are returned directly, for lists and dicts :func:`parse_dict` or :func:`parse_list`
are called
"""
token = lexer.next()
token = lexer.get_token()
if token == '%':
variable_name = lexer.next()
nt = lexer.next()
variable_name = lexer.get_token()
nt = lexer.get_token()
assert nt == "=", "Expected equal sign; got %s" % nt
return self.unquote(variable_name), self.parse_dict(lexer)
@ -73,10 +72,10 @@ class DataDumperReader(object):
return self.parse_list(lexer)
if token == '$':
variable_name = lexer.next()
nt = lexer.next()
variable_name = lexer.get_token()
nt = lexer.get_token()
assert nt == "=", "Expected equal sign; got %s" % nt
return variable_name, lexer.next()
return variable_name, lexer.get_token()
return self.unquote(token)
@ -84,7 +83,7 @@ class DataDumperReader(object):
"""Parses the current structure block into a python dict. Calls :func:`parse_structure` for each
value in the dictionary"""
token = lexer.next()
token = lexer.get_token()
assert token in ('(', '{'), "Expected '(' or '{'; got %s" % token
d = {}
@ -96,7 +95,7 @@ class DataDumperReader(object):
continue
variable_name = token
nt = lexer.next() + lexer.next()
nt = lexer.get_token() + lexer.get_token()
assert nt == "=>", "Expected '=>'; got %s" % nt
d[self.unquote(variable_name)] = self.parse_structure(lexer)
@ -106,7 +105,7 @@ class DataDumperReader(object):
"""Parses the current structure block into a python list. Calls :func:`parse_structure` for each
value."""
token = lexer.next()
token = lexer.get_token()
assert token == '[', "Expected '['; got %s" % token
l = []
@ -121,7 +120,7 @@ class DataDumperReader(object):
list_item = self.parse_structure(lexer)
l.append(list_item)
nt = lexer.next()
nt = lexer.get_token()
if nt == ']':
break
assert nt == ",", "Expected ','; got %s" % nt

10
tests/test_perlcrap.py

@ -19,7 +19,7 @@ class PerlCrapTestCase(SimpleTestCase):
d = self.parse_and_assert(s, reader)
self.assertEqual(len(d), 1)
self.assertEqual(d.keys()[0], hash_name)
self.assertEqual(list(d)[0], hash_name)
obj = d[hash_name]
if assert_isinstance:
@ -32,7 +32,7 @@ class PerlCrapTestCase(SimpleTestCase):
d = self.parse_and_assert(s)
self.assertEqual(len(d), 1)
self.assertEqual(d.keys()[0], 'foobar')
self.assertEqual(list(d)[0], 'foobar')
self.assertEqual(d['foobar'], '1')
def test_escaped_quotes(self):
@ -40,7 +40,7 @@ class PerlCrapTestCase(SimpleTestCase):
d = self.parse_and_assert(s)
self.assertEqual(len(d), 1)
self.assertEqual(d.keys()[0], 'foobar')
self.assertEqual(list(d)[0], 'foobar')
self.assertEqual(d['foobar'], "foo's bar")
def test_invalid_input(self):
@ -69,7 +69,7 @@ class PerlCrapTestCase(SimpleTestCase):
d = self.parse_and_assert_hash(s, assert_isinstance=dict)
self.assertEqual(len(d), 1)
self.assertEqual(d.keys()[0], 'foobar')
self.assertEqual(list(d)[0], 'foobar')
l = d['foobar']
self.assertTrue(isinstance(l, list))
@ -84,7 +84,7 @@ class PerlCrapTestCase(SimpleTestCase):
d = self.parse_and_assert_hash(s, assert_isinstance=dict)
self.assertEqual(len(d), 1)
self.assertEqual(d.keys()[0], 'foobar')
self.assertEqual(list(d)[0], 'foobar')
l = d['foobar']
self.assertTrue(isinstance(l, list))