Index: cms/tests/static_tests/conftest.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/cms/tests/static_tests/conftest.py |
@@ -0,0 +1,45 @@ |
+import os |
+import pytest |
+import subprocess |
+ |
+SOURCEPATH = 'cms/tests/test_site/pages/' |
+STATICPATH = 'cms/tests/static_out/' |
+ |
+ |
+@pytest.fixture(scope='session', autouse=True) |
+def static_session_setup(request): |
+ seen = set() |
+ session = request.node |
+ for item in session.items: |
+ cls = item.getparent(pytest.Class) |
+ if cls not in seen: |
+ if hasattr(cls.obj, 'generate_static_test_pages'): |
+ cls.obj.generate_static_test_pages() |
+ seen.add(cls) |
+ |
+ def static_tear_down(): |
+ subprocess.check_call(['rm', '-r', 'cms/tests/test_site/.hg']) |
+ subprocess.check_call(['rm', '-r', 'cms/tests/static_out']) |
+ request.addfinalizer(static_tear_down) |
+ |
+ |
+@pytest.fixture(scope='session') |
+def input_files(): |
+ return_data = {} |
+ print os.walk(SOURCEPATH) |
+ for (dirpath, dirnames, filenames) in os.walk(SOURCEPATH): |
+ for input_file in filenames: |
+ with open('{}/{}'.format(dirpath, input_file)) as f: |
+ return_data[input_file] = f.read() |
+ print return_data |
+ return return_data |
+ |
+ |
+@pytest.fixture(scope='session') |
+def output_files(): |
+ return_data = {} |
+ for (dirpath, dirnames, filenames) in os.walk(STATICPATH): |
+ for output_file in filenames: |
+ with open('{}/{}'.format(dirpath, output_file)) as f: |
+ return_data[output_file] = f.read() |
+ return return_data |