selftest.target: Add NoneTarget.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 4 Mar 2012 15:01:18 +0000 (16:01 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 4 Mar 2012 17:02:07 +0000 (18:02 +0100)
selftest/target/__init__.py
selftest/tests/test_target.py

index b6a297c..4c95c74 100644 (file)
@@ -29,6 +29,14 @@ class EnvironmentDown(Exception):
         super(EnvironmentDown, self).__init__("environment went down: %s" % msg)
 
 
+class UnsupportedEnvironment(Exception):
+    """Indicates a particular environment is not supported."""
+
+    def __init__(self, target, envname):
+        super(UnsupportedEnvironment, self).__init__(
+            "Target %s does not support environment %s" % (target, envname))
+
+
 class Target(object):
     """A target for Samba tests."""
 
@@ -93,6 +101,15 @@ class NoneEnvironment(Environment):
         return {}
 
 
+class NoneTarget(Target):
+    """Target that can only provide the 'none' environment."""
+
+    name = "none"
+
+    def setup_env(self, envname, prefix):
+        raise UnsupportedEnvironment(self.name, envname)
+
+
 class EnvironmentManager(object):
     """Manager of environments."""
 
index 0a5d1c4..139ed74 100644 (file)
@@ -24,7 +24,9 @@ from selftest.target import (
     EnvironmentDown,
     EnvironmentManager,
     NoneEnvironment,
+    NoneTarget,
     Target,
+    UnsupportedEnvironment,
     )
 
 import unittest
@@ -67,6 +69,17 @@ class NoneEnvironmentTests(unittest.TestCase):
         self.assertEquals("", self.env.get_log())
 
 
+class NoneTargetTests(unittest.TestCase):
+
+    def setUp(self):
+        super(NoneTargetTests, self).setUp()
+        self.target = NoneTarget()
+
+    def test_setup_env(self):
+        self.assertRaises(UnsupportedEnvironment, self.target.setup_env,
+            "something", "prefx")
+
+
 class EnvironmentManagerTests(unittest.TestCase):
 
     def setUp(self):