[damned-lies] Removed obsolete test imports and moved test utilities



commit 853528978b4e69f7ac004eeec9aaf12a00b46f5d
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Mar 2 20:55:09 2017 +0100

    Removed obsolete test imports and moved test utilities

 stats/tests/__init__.py    |    2 -
 stats/tests/tests.py       |   50 +-------------------------------------
 stats/tests/utils.py       |   58 ++++++++++++++++++++++++++++++++++++++++++++
 vertimus/tests/__init__.py |    2 -
 vertimus/tests/tests.py    |   10 ++++++-
 5 files changed, 67 insertions(+), 55 deletions(-)
---
diff --git a/stats/tests/__init__.py b/stats/tests/__init__.py
index 1ae7f52..e69de29 100644
--- a/stats/tests/__init__.py
+++ b/stats/tests/__init__.py
@@ -1,2 +0,0 @@
-# Temporary import to accomodate for Django < 1.6
-from .tests import *
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 43cff18..7ec05f7 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -1,10 +1,8 @@
 import json
 import os
 import shutil
-import tarfile
 import tempfile
 from datetime import date
-from functools import wraps
 from unittest import skipUnless
 
 from django.conf import settings
@@ -21,26 +19,7 @@ from stats.models import (
 from stats import utils
 from languages.models import Language
 
-
-def test_scratchdir(test_func):
-    """ Decorator to temporarily use the scratchdir inside the test directory """
-    @wraps(test_func)
-    def decorator(self):
-        old_SCRATCHDIR = settings.SCRATCHDIR
-        old_POTDIR = settings.POTDIR
-        settings.SCRATCHDIR = os.path.join(tempfile.mkdtemp(), 'scratch')
-        settings.POTDIR = os.path.join(settings.SCRATCHDIR, "POT")
-        os.makedirs(settings.POTDIR)
-        tar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'gnome-hello.tar.gz')
-        with tarfile.open(tar_path) as gnome_hello_tar:
-            gnome_hello_tar.extractall(os.path.join(settings.SCRATCHDIR, 'git'))
-        try:
-            test_func(self)
-        finally:
-            shutil.rmtree(settings.SCRATCHDIR)
-            settings.SCRATCHDIR = old_SCRATCHDIR
-            settings.POTDIR = old_POTDIR
-    return decorator
+from .utils import patch_shell_command, test_scratchdir
 
 def mocked_checkout(branch):
     """ Replace real vcs checkout by a mocked method """
@@ -48,33 +27,6 @@ def mocked_checkout(branch):
         raise
     return
 
-class patch_shell_command:
-    """
-    Mock utils.run_shell_commands and gather all passed commands.
-    `only` is an optional list of commands to limit mocking to (empty -> all).
-    """
-    def __init__(self, only=None):
-        self.only = only
-
-    def __enter__(self):
-        self.cmds = []
-        self.saved_run_shell_command = utils.run_shell_command
-        utils.run_shell_command = self.mocked_run_shell_command
-        return self.cmds
-
-    def mocked_run_shell_command(self, cmd, *args, **kwargs):
-        cmd_str = " ".join(cmd) if isinstance(cmd, list) else cmd
-        self.cmds.append(cmd_str)
-        if self.only is not None and not any(needle in cmd_str for needle in self.only):
-            # Pass the command to the real utils.run_shell_command
-            return self.saved_run_shell_command(cmd, *args, **kwargs)
-        else:
-            # Pretend the command was successfull
-            return 0, '', ''
-
-    def __exit__(self, *args):
-        utils.run_shell_command = self.saved_run_shell_command
-
 
 class ModuleTestCase(TestCase):
     fixtures = ['sample_data.json']
diff --git a/stats/tests/utils.py b/stats/tests/utils.py
new file mode 100644
index 0000000..6822e03
--- /dev/null
+++ b/stats/tests/utils.py
@@ -0,0 +1,58 @@
+import os
+import shutil
+import tarfile
+import tempfile
+from functools import wraps
+
+from django.conf import settings
+
+from stats import utils
+
+
+class patch_shell_command:
+    """
+    Mock utils.run_shell_commands and gather all passed commands.
+    `only` is an optional list of commands to limit mocking to (empty -> all).
+    """
+    def __init__(self, only=None):
+        self.only = only
+
+    def __enter__(self):
+        self.cmds = []
+        self.saved_run_shell_command = utils.run_shell_command
+        utils.run_shell_command = self.mocked_run_shell_command
+        return self.cmds
+
+    def mocked_run_shell_command(self, cmd, *args, **kwargs):
+        cmd_str = " ".join(cmd) if isinstance(cmd, list) else cmd
+        self.cmds.append(cmd_str)
+        if self.only is not None and not any(needle in cmd_str for needle in self.only):
+            # Pass the command to the real utils.run_shell_command
+            return self.saved_run_shell_command(cmd, *args, **kwargs)
+        else:
+            # Pretend the command was successfull
+            return 0, '', ''
+
+    def __exit__(self, *args):
+        utils.run_shell_command = self.saved_run_shell_command
+
+
+def test_scratchdir(test_func):
+    """ Decorator to temporarily use the scratchdir inside the test directory """
+    @wraps(test_func)
+    def decorator(self):
+        old_SCRATCHDIR = settings.SCRATCHDIR
+        old_POTDIR = settings.POTDIR
+        settings.SCRATCHDIR = os.path.join(tempfile.mkdtemp(), 'scratch')
+        settings.POTDIR = os.path.join(settings.SCRATCHDIR, "POT")
+        os.makedirs(settings.POTDIR)
+        tar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'gnome-hello.tar.gz')
+        with tarfile.open(tar_path) as gnome_hello_tar:
+            gnome_hello_tar.extractall(os.path.join(settings.SCRATCHDIR, 'git'))
+        try:
+            test_func(self)
+        finally:
+            shutil.rmtree(settings.SCRATCHDIR)
+            settings.SCRATCHDIR = old_SCRATCHDIR
+            settings.POTDIR = old_POTDIR
+    return decorator
diff --git a/vertimus/tests/__init__.py b/vertimus/tests/__init__.py
index 1ae7f52..e69de29 100644
--- a/vertimus/tests/__init__.py
+++ b/vertimus/tests/__init__.py
@@ -1,2 +0,0 @@
-# Temporary import to accomodate for Django < 1.6
-from .tests import *
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 29547f5..06a0b84 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -11,10 +11,16 @@ from django.http import QueryDict
 from django.test.utils import override_settings
 from django.utils.datastructures import MultiValueDict
 
+from people.models import Person
+from teams.models import Role
 from teams.tests import TeamsAndRolesTests
 from stats.models import Module, Branch, Release, Category, CategoryName, Domain, Statistics
-from stats.tests import patch_shell_command, test_scratchdir
-from vertimus.models import *
+from stats.tests.utils import patch_shell_command, test_scratchdir
+from vertimus.models import (
+    Action, ActionArchived, ActionCI, ActionUNDO, ActionWC, State, StateCommitted,
+    StateCommitting, StateNone, StateProofread, StateProofreading, StateToCommit,
+    StateToReview, StateTranslated, StateTranslating,
+)
 from vertimus.forms import ActionForm
 
 MEDIA_ROOT = tempfile.mkdtemp()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]