| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import os | |
| 2 import sys | |
| 3 import shutil | |
| 4 import time | |
| 5 import runpy | |
| 6 import pytest | |
| 7 import urllib2 | |
| 8 import subprocess | |
| 9 | |
| 10 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| 11 | |
| 12 | |
| 13 def get_expected_outputs(): | |
| 14 return_data = {} | |
| 15 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') | |
| 16 for (dirpath, dirnames, filenames) in os.walk(expected_out_path): | |
|
Vasily Kuznetsov
2016/07/12 15:25:11
You actually don't need the parentheses around `di
| |
| 17 for output_file in filenames: | |
| 18 with open('{}/{}'.format(dirpath, output_file)) as f: | |
|
Vasily Kuznetsov
2016/07/12 15:25:11
Here it's also better to use `os.path.join`.
| |
| 19 return_data[output_file] = f.read() | |
| 20 return return_data | |
| 21 | |
| 22 expected_outputs = get_expected_outputs() | |
| 23 | |
| 24 | |
| 25 @pytest.fixture(scope='session') | |
| 26 def temp_site(tmpdir_factory): | |
| 27 site_dir = tmpdir_factory.mktemp('temp_out') | |
|
Vasily Kuznetsov
2016/07/12 15:25:11
Maybe better call this `out_dir`. Otherwise `site_
| |
| 28 | |
| 29 site_dir = site_dir.join('test_site').strpath | |
| 30 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) | |
| 31 subprocess.check_call(['hg', 'init', site_dir]) | |
| 32 subprocess.check_call( | |
|
Vasily Kuznetsov
2016/07/12 15:25:10
This call seems to fit on one line, so there's no
| |
| 33 [ | |
| 34 'hg', '-R', site_dir, | |
| 35 'commit', '-A', '-m', 'foo', | |
| 36 ] | |
| 37 ) | |
| 38 return site_dir | |
| 39 | |
| 40 | |
| 41 @pytest.fixture(scope='session') | |
| 42 def static_output(request, temp_site): | |
| 43 static_out_path = os.path.join(temp_site, 'static_out') | |
| 44 sys.argv = ['filler', temp_site, static_out_path] | |
| 45 | |
| 46 runpy.run_module( | |
|
Vasily Kuznetsov
2016/07/12 15:25:12
This one also fits on one line.
| |
| 47 'cms.bin.generate_static_pages', run_name='__main__' | |
| 48 ) | |
| 49 return static_out_path | |
| 50 | |
| 51 | |
| 52 @pytest.fixture(scope='session') | |
|
Vasily Kuznetsov
2016/07/12 15:25:12
It seems that with current default version of pyte
Jon Sonesen
2016/07/18 14:48:27
It works but I believe I am still using the pytest
| |
| 53 def dynamic_server(temp_site): | |
| 54 p = subprocess.Popen( | |
|
Vasily Kuznetsov
2016/07/12 15:25:11
This also fits on one line.
| |
| 55 ['python', 'runserver.py', temp_site] | |
| 56 ) | |
| 57 time.sleep(0.5) | |
| 58 yield 'http://localhost:5000/root/' | |
| 59 p.terminate() | |
| 60 | |
| 61 | |
| 62 @pytest.fixture(scope='session') | |
| 63 def output_pages(static_output): | |
| 64 return_data = {} | |
| 65 for (dirpath, dirnames, filenames) in os.walk(static_output): | |
|
Vasily Kuznetsov
2016/07/12 15:25:12
This code seems to be duplicated from `get_expecte
| |
| 66 for output_file in filenames: | |
| 67 with open('{}/{}'.format(dirpath, output_file)) as f: | |
| 68 return_data[output_file] = f.read() | |
| 69 return return_data | |
| 70 | |
| 71 | |
| 72 @pytest.mark.parametrize('filename,expected_output', expected_outputs.items()) | |
|
Vasily Kuznetsov
2016/07/12 15:25:10
It seems that we're not using `expected_output` as
| |
| 73 def test_static(output_pages, filename, expected_output): | |
| 74 assert output_pages[filename] == expected_output | |
| 75 | |
| 76 | |
| 77 @pytest.mark.parametrize('filename,expected_output', expected_outputs.items()) | |
| 78 def test_dynamic(dynamic_server, filename, expected_output): | |
| 79 response = urllib2.urlopen(dynamic_server + filename) | |
| 80 assert response.read() == expected_output | |
| OLD | NEW |