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

Unified Diff: tests/utils.py

Issue 29886648: Issue #6942 - Add XTM integration in CMS (Closed)
Patch Set: Addressed initial comments Created Sept. 25, 2018, 12:24 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/utils.py
diff --git a/tests/utils.py b/tests/utils.py
index 2d972259e02c9c6cf6c178eea263ea2a94ce9adf..1683c2d02c3ae68194bb02c5e3421679d94b31b5 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -18,6 +18,9 @@ import os
import signal
import subprocess
import time
+import zipfile
+from io import BytesIO
+import pytest
Vasily Kuznetsov 2018/09/26 15:45:27 Nit: there should be an empty line before pytest,
Tudor Avram 2018/10/04 06:48:15 Done.
def get_dir_contents(path):
@@ -47,3 +50,36 @@ def run_test_server(site_path):
time.sleep(0.5)
yield 'http://localhost:5000/'
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
+
+
+def create_in_memory_zip(file_names, file_data):
+ """Create a BytesIO object with the contents of a zip file.
+
+ Parameters
+ ----------
+ file_names: iterable
+ Of file names. Should be the full paths of the file inside the zip.
+ file_data: iterable
+ The data to be contained of the files.
+
+ Returns
+ -------
+ BytesIO
+ The resulting in-memory zip file.
+
+ """
+ memory_zip = BytesIO()
+
+ with zipfile.ZipFile(memory_zip, 'w') as zf:
+ for idx in range(len(file_names)):
+ zf.writestr(file_names[idx], file_data[idx], zipfile.ZIP_DEFLATED)
+
+ memory_zip.seek(0)
+ return memory_zip
+
+
+def exception_test(func, exception, exp_msg, *args, **kw):
+ with pytest.raises(exception) as err:
+ func(*args, **kw)
+
+ assert exp_msg in str(err.value)

Powered by Google App Engine
This is Rietveld