Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_render_script.py

Issue 29341320: Noissue - Added flake8-abp and pep8-naming extension and fix reported warnings (Closed)
Patch Set: Fixed some broken string literals in Python 2 Created May 12, 2016, 3:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « setup.py ('k') | tests/test_renderer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 25 matching lines...) Expand all
36 36
37 @pytest.fixture 37 @pytest.fixture
38 def rootdir(tmpdir): 38 def rootdir(tmpdir):
39 """Directory with prepared list fragments.""" 39 """Directory with prepared list fragments."""
40 rootdir = tmpdir.join('root') 40 rootdir = tmpdir.join('root')
41 rootdir.mkdir() 41 rootdir.mkdir()
42 # Simple file with just `Ok` and a non-ascii unicode character in it. 42 # Simple file with just `Ok` and a non-ascii unicode character in it.
43 rootdir.join('simple.txt').write('[Adblock]\nOk') 43 rootdir.join('simple.txt').write('[Adblock]\nOk')
44 # Fragment with a non-ascii character. 44 # Fragment with a non-ascii character.
45 rootdir.join('unicode.txt').write( 45 rootdir.join('unicode.txt').write(
46 '[Adblock]\n\u1234'.encode('utf-8'), mode='wb') 46 u'[Adblock]\n\u1234'.encode('utf-8'), mode='wb')
Sebastian Noack 2016/05/12 15:31:03 Since, for whatever reason, the qa env did run wit
Sebastian Noack 2016/05/27 12:54:55 I reverted changes of patch set 2. My conclusion a
47 # Fragment with an include. 47 # Fragment with an include.
48 rootdir.join('includer.txt').write('[Adblock]\n%include inc:includee.txt%') 48 rootdir.join('includer.txt').write('[Adblock]\n%include inc:includee.txt%')
49 # Fragment that includes a circular include file. 49 # Fragment that includes a circular include file.
50 rootdir.join('circ.txt').write('[Adblock]\n%include inc:circular.txt%') 50 rootdir.join('circ.txt').write('[Adblock]\n%include inc:circular.txt%')
51 # Fragment that includes a file with broken include. 51 # Fragment that includes a file with broken include.
52 rootdir.join('brk.txt').write('[Adblock]\n%include inc:broken.txt%') 52 rootdir.join('brk.txt').write('[Adblock]\n%include inc:broken.txt%')
53 # Source directory for includes. 53 # Source directory for includes.
54 incdir = rootdir.join('inc') 54 incdir = rootdir.join('inc')
55 incdir.mkdir() 55 incdir.mkdir()
56 # Fragment that's included into includer.txt. 56 # Fragment that's included into includer.txt.
57 incdir.join('includee.txt').write('I am included!') 57 incdir.join('includee.txt').write('I am included!')
58 # Fragment that has a broken include. 58 # Fragment that has a broken include.
59 incdir.join('broken.txt').write('%include missing.txt%') 59 incdir.join('broken.txt').write('%include missing.txt%')
60 # Fragment that includes itself. 60 # Fragment that includes itself.
61 incdir.join('circular.txt').write('%include circular.txt%') 61 incdir.join('circular.txt').write('%include circular.txt%')
62 return rootdir 62 return rootdir
63 63
64 64
65 @pytest.fixture 65 @pytest.fixture
66 def webserver_port(tmpdir, request): 66 def webserver_port(tmpdir, request):
67 """Serve fragments via HTTP on a random port (return the port number).""" 67 """Serve fragments via HTTP on a random port (return the port number)."""
68 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler 68 handler = SimpleHTTPServer.SimpleHTTPRequestHandler
69 httpd = SocketServer.TCPServer(("", 0), Handler) 69 httpd = SocketServer.TCPServer(('', 0), handler)
70 port = httpd.socket.getsockname()[1] 70 port = httpd.socket.getsockname()[1]
71 # Create some files to serve. 71 # Create some files to serve.
72 webroot = tmpdir.join('webroot') 72 webroot = tmpdir.join('webroot')
73 webroot.mkdir() 73 webroot.mkdir()
74 webroot.join('inc.txt').write('Web \u1234'.encode('utf-8'), mode='wb') 74 webroot.join('inc.txt').write(u'Web \u1234'.encode('utf-8'), mode='wb')
75 webroot.join('metainc.txt').write( 75 webroot.join('metainc.txt').write(
76 '%include http://localhost:{}/inc.txt%'.format(port)) 76 '%include http://localhost:{}/inc.txt%'.format(port))
77 # Change to this directory and start the webserver in another thread. 77 # Change to this directory and start the webserver in another thread.
78 os.chdir(str(webroot)) 78 os.chdir(str(webroot))
79 thread = threading.Thread(target=httpd.serve_forever) 79 thread = threading.Thread(target=httpd.serve_forever)
80 thread.setDaemon(True) 80 thread.setDaemon(True)
81 thread.start() 81 thread.start()
82 # Make sure we shut it down at the end of the test. 82 # Make sure we shut it down at the end of the test.
83 request.addfinalizer(httpd.shutdown) 83 request.addfinalizer(httpd.shutdown)
84 return port 84 return port
(...skipping 15 matching lines...) Expand all
100 100
101 def test_render_no_includes(rootdir, dstfile): 101 def test_render_no_includes(rootdir, dstfile):
102 run_script(str(rootdir.join('simple.txt')), str(dstfile)) 102 run_script(str(rootdir.join('simple.txt')), str(dstfile))
103 result = dstfile.read() 103 result = dstfile.read()
104 assert 'Ok' in result 104 assert 'Ok' in result
105 assert '! Checksum:' in result 105 assert '! Checksum:' in result
106 106
107 107
108 def test_render_unicode(rootdir, dstfile): 108 def test_render_unicode(rootdir, dstfile):
109 code, err = run_script(str(rootdir.join('unicode.txt')), str(dstfile)) 109 code, err = run_script(str(rootdir.join('unicode.txt')), str(dstfile))
110 assert '\u1234' in dstfile.read(mode='rb').decode('utf-8') 110 assert u'\u1234' in dstfile.read(mode='rb').decode('utf-8')
111 111
112 112
113 def test_render_with_includes(rootdir, dstfile): 113 def test_render_with_includes(rootdir, dstfile):
114 run_script(str(rootdir.join('includer.txt')), str(dstfile), 114 run_script(str(rootdir.join('includer.txt')), str(dstfile),
115 '-i', 'inc=' + str(rootdir.join('inc'))) 115 '-i', 'inc=' + str(rootdir.join('inc')))
116 assert 'I am included!' in dstfile.read() 116 assert 'I am included!' in dstfile.read()
117 117
118 118
119 def test_render_with_includes_relative(rootdir, dstfile): 119 def test_render_with_includes_relative(rootdir, dstfile):
120 run_script('includer.txt', str(dstfile), '-i', 'inc=inc', cwd=str(rootdir)) 120 run_script('includer.txt', str(dstfile), '-i', 'inc=inc', cwd=str(rootdir))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 assert err == "Unknown source: 'foo'\n" 171 assert err == "Unknown source: 'foo'\n"
172 172
173 173
174 @pytest.mark.tryfirst 174 @pytest.mark.tryfirst
175 @pytest.mark.slowtest 175 @pytest.mark.slowtest
176 def test_web_include(rootdir, dstfile, webserver_port): 176 def test_web_include(rootdir, dstfile, webserver_port):
177 url = 'http://localhost:{}/metainc.txt'.format(webserver_port) 177 url = 'http://localhost:{}/metainc.txt'.format(webserver_port)
178 webinc = rootdir.join('webinc.txt') 178 webinc = rootdir.join('webinc.txt')
179 webinc.write('[Adblock]\n%include {}%'.format(url)) 179 webinc.write('[Adblock]\n%include {}%'.format(url))
180 code, err = run_script(str(webinc), str(dstfile)) 180 code, err = run_script(str(webinc), str(dstfile))
181 assert 'Web \u1234' in dstfile.read(mode='rb').decode('utf-8') 181 assert u'Web \u1234' in dstfile.read(mode='rb').decode('utf-8')
182 182
183 183
184 @pytest.mark.slowtest 184 @pytest.mark.slowtest
185 def test_failed_web_include(rootdir, dstfile, webserver_port): 185 def test_failed_web_include(rootdir, dstfile, webserver_port):
186 url = 'http://localhost:{}/missing.txt'.format(webserver_port) 186 url = 'http://localhost:{}/missing.txt'.format(webserver_port)
187 webinc = rootdir.join('webinc.txt') 187 webinc = rootdir.join('webinc.txt')
188 webinc.write('[Adblock]\n%include {}%'.format(url)) 188 webinc.write('[Adblock]\n%include {}%'.format(url))
189 code, err = run_script(str(webinc), str(dstfile)) 189 code, err = run_script(str(webinc), str(dstfile))
190 assert code == 1 190 assert code == 1
191 assert err.startswith( 191 assert err.startswith(
192 "HTTP 404 Not found: '{0}' when including '{0}'".format(url)) 192 "HTTP 404 Not found: '{0}' when including '{0}'".format(url))
OLDNEW
« no previous file with comments | « setup.py ('k') | tests/test_renderer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld