Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tests for Execute.only_if

  • Loading branch information...
commit 485f22d8776ce49b4b1443434a870cff88470ca3 1 parent 9d41322
@samuel authored
Showing with 27 additions and 1 deletion.
  1. +1 −1  kokki/environment.py
  2. +26 −0 tests/__init__.py
View
2  kokki/environment.py
@@ -92,7 +92,7 @@ def run(self):
if resource.not_if is not None and self._check_condition(resource.not_if):
self.log.debug("Skipping %s due to not_if" % resource)
continue
-
+
if resource.only_if is not None and not self._check_condition(resource.only_if):
self.log.debug("Skipping %s due to only_if" % resource)
continue
View
26 tests/__init__.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import os
+import shutil
+import tempfile
import unittest
from kokki import *
@@ -29,5 +31,29 @@ def testOverrideConfig(self):
self.failUnlessEqual("manchu", self.kit.config.test.config2)
self.failUnlessEqual("manchu", self.kit._test)
+class TestExecute(unittest.TestCase):
+ def setUp(self):
+ self.temp_path = tempfile.mkdtemp(suffix="kokki-tests")
+
+ def tearDown(self):
+ shutil.rmtree(self.temp_path)
+
+ def testOnlyIf(self):
+ with Environment() as env:
+ temp_file = os.path.join(self.temp_path, "exists")
+ Execute("touch %s-lamba-false" % temp_file,
+ only_if = lambda:False)
+ Execute("touch %s-cmd-false" % temp_file,
+ only_if = "false")
+ Execute("touch %s-lambda-true" % temp_file,
+ only_if = lambda:True)
+ Execute("touch %s-cmd-true" % temp_file,
+ only_if = "true")
+ env.run()
+ self.failIf(os.path.exists(temp_file+"-lambda-false"))
+ self.failIf(os.path.exists(temp_file+"-cmd-false"))
+ self.failUnless(os.path.exists(temp_file+"-lambda-true"))
+ self.failUnless(os.path.exists(temp_file+"-cmd-true"))
+
if __name__ == '__main__':
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.