Klaus Demo ~jonashaag/klaus / bcd646f
Some Python 3 fixes Jonas Haag 6 years ago
8 changed file(s) with 39 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
22 python:
33 - "2.6"
44 - "2.7"
5 - "3.4"
6 - "3.5"
57 addons:
68 apt:
79 packages:
5656 args = make_parser().parse_args()
5757
5858 if args.version:
59 print KLAUS_VERSION
59 print(KLAUS_VERSION)
6060 return 0
6161
6262 if args.htdigest and not args.smarthttp:
63 print >> sys.stderr, "ERROR: --htdigest option has no effect without --smarthttp enabled"
63 print("ERROR: --htdigest option has no effect without --smarthttp enabled", file=sys.stderr)
6464 return 1
6565
6666 if not args.repos:
67 print >> sys.stderr, "WARNING: No repositories supplied -- syntax is 'klaus dir1 dir2...'."
67 print("WARNING: No repositories supplied -- syntax is 'klaus dir1 dir2...'.", file=sys.stderr)
6868
6969 if not args.site_name:
7070 args.site_name = '%s:%d' % (args.host, args.port)
7272 if args.ctags != 'none':
7373 from klaus.ctagsutils import check_have_exuberant_ctags
7474 if not check_have_exuberant_ctags():
75 print >> sys.stderr, "ERROR: Exuberant ctags not installed (or 'ctags' binary isn't *Exuberant* ctags)"
75 print("ERROR: Exuberant ctags not installed (or 'ctags' binary isn't *Exuberant* ctags)", file=sys.stderr)
7676 return 1
7777 try:
7878 import ctags
77 def check_have_exuberant_ctags():
88 """Check that the 'ctags' binary is *Exuberant* ctags (not etags etc)"""
99 try:
10 return "Exuberant" in check_output(["ctags", "--version"], stderr=subprocess.PIPE)
10 return b"Exuberant" in check_output(["ctags", "--version"], stderr=subprocess.PIPE)
1111 except subprocess.CalledProcessError:
1212 return False
1313
1212 tests="tests/"
1313 fi
1414
15 py.test $tests -v
15 PYTHONPATH=tests py.test $tests -v
44 def test_dont_show_blame_link():
55 with serve():
66 for file in ["binary", "image.jpg", "toolarge"]:
7 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/" + file).content
7 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/" + file).text
88 assert "blame" not in response
99
1010
1212 """Don't render blame even if someone navigated to the blame site by accident."""
1313 with serve():
1414 for file in ["binary", "image.jpg", "toolarge"]:
15 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blame/HEAD/" + file).content
15 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blame/HEAD/" + file).text
1616 assert "Can't show blame" in response
00 import os
11 import re
2 import sys
23 import subprocess
34 import tempfile
45 import shutil
910 import requests.auth
1011
1112 from .utils import *
13
14
15 xfail_py3 = pytest.mark.xfail(sys.version_info.major >= 3, reason="not supported on Python 3")
1216
1317
1418 def test_htdigest_file_without_smarthttp_or_require_browser_auth():
5458 {'use_smarthttp': True},
5559 {'reach': True, 'clone': True, 'push': False}
5660 )
57 test_smart_push = options_test(
61 test_smart_push = xfail_py3(options_test(
5862 {'use_smarthttp': True, 'htdigest_file': open(HTDIGEST_FILE)},
5963 {'reach': True, 'clone': True, 'push_auth': True, 'push_unauth': False}
60 )
61 test_unauthenticated_push = options_test(
64 ))
65 test_unauthenticated_push = xfail_py3(options_test(
6266 {'use_smarthttp': True, 'unauthenticated_push': True},
6367 {'reach': True, 'clone': True, 'push': True}
64 )
68 ))
6569 test_nosmart_auth = options_test(
6670 {'require_browser_auth': True, 'htdigest_file': open(HTDIGEST_FILE)},
6771 {'reach_auth': True, 'reach_unauth': False, 'clone': False, 'push': False}
6872 )
69 test_smart_auth = options_test(
73 test_smart_auth = xfail_py3(options_test(
7074 {'require_browser_auth': True, 'use_smarthttp': True, 'htdigest_file': open(HTDIGEST_FILE)},
7175 {'reach_auth': True, 'reach_unauth': False, 'clone_auth': True, 'clone_unauth': False, 'push_unauth': False, 'push_auth': True}
72 )
76 ))
7377 test_smart_auth_disable_push = options_test(
7478 {'require_browser_auth': True, 'use_smarthttp': True, 'disable_push': True, 'htdigest_file': open(HTDIGEST_FILE)},
7579 {'reach_auth': True, 'reach_unauth': False, 'clone_auth': True, 'clone_unauth': False, 'push': False}
7983 {},
8084 {'ctags_tags_and_branches': False, 'ctags_all': False}
8185 )
82 test_ctags_tags_and_branches = options_test(
86 test_ctags_tags_and_branches = xfail_py3(options_test(
8387 {'ctags_policy': 'tags-and-branches'},
8488 {'ctags_tags_and_branches': True, 'ctags_all': False}
85 )
86 test_ctags_all = options_test(
89 ))
90 test_ctags_all = xfail_py3(options_test(
8791 {'ctags_policy': 'ALL'},
8892 {'ctags_tags_and_branches': True, 'ctags_all': True}
89 )
93 ))
9094
9195
9296 # Reach
108112 tmp = tempfile.mkdtemp()
109113 try:
110114 return any([
111 b"git clone" in http_get(TEST_REPO_URL).content,
115 "git clone" in http_get(TEST_REPO_URL).text,
112116 _check_http200(http_get, TEST_REPO_URL + "info/refs?service=git-upload-pack"),
113117 subprocess.call(["git", "clone", url, tmp]) == 0,
114118 ])
141145
142146 def ctags_all():
143147 all_refs = re.findall('href=".+/commit/([a-z0-9]{40})/">',
144 requests.get(UNAUTH_TEST_REPO_URL).content)
148 requests.get(UNAUTH_TEST_REPO_URL).text)
145149 assert len(all_refs) == 3
146150 return all(
147151 _ctags_enabled(ref, f)
151155 def _ctags_enabled(ref, filename):
152156 response = requests.get(UNAUTH_TEST_REPO_URL + "blob/%s/%s" % (ref, filename))
153157 href = '<a href="/%sblob/%s/%s#L-1">' % (TEST_REPO_URL, ref, filename)
154 return href in response.content
158 return href in response.text
155159
156160
157161 def _GET_unauth(url=""):
0 import sys
1 import re
02 import klaus_cli
1 import mock
2 from klaus.utils import check_output
3 import re
3 try:
4 from unittest import mock
5 except ImportError:
6 import mock
7 from klaus.utils import check_output, force_unicode
48
59
610 def test_covers_all_cli_options():
7 manpage = check_output(["man", "./klaus.1"])
11 manpage = force_unicode(check_output(["man", "./klaus.1"]))
812
913 def assert_in_manpage(s):
1014 clean = lambda x: re.sub('(.\\x08)|\s', '', x)
1515
1616 def test_no_newline_at_end_of_file():
1717 with serve():
18 response = requests.get(TEST_REPO_NO_NEWLINE_URL + "commit/HEAD/").content
18 response = requests.get(TEST_REPO_NO_NEWLINE_URL + "commit/HEAD/").text
1919 assert "No newline at end of file" in response
2020 assert "2<del></del>" in response
2121 assert "2<ins></ins>" in response
2323
2424 def test_dont_render_binary():
2525 with serve():
26 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/binary").content
26 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/binary").text
2727 assert "Binary data not shown" in response
2828
2929
3030 def test_render_image():
3131 with serve():
32 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/image.jpg").content
32 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/image.jpg").text
3333 assert '<img src="/dont-render/raw/HEAD/image.jpg"' in response
3434
3535
3636 def test_dont_render_large_file():
3737 with serve():
38 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/toolarge").content
38 response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/toolarge").text
3939 assert "Large file not shown" in response