Commits

Vladimir Mihailenco  committed 151a99a

Clean up tests

  • Participants
  • Parent commits 3001dc9

Comments (0)

Files changed (7)

File fabdeploy/containers.py

     def os(self):
         from fabdeploy import system
         with system.os_codename.tmp_conf():
-            self.set_globally('os', system.os_codename.codename())
+            self.set_globally('os', system.os_codename.os_codename())
         return self.os
 
     @conf

File fabdeploy/system.py

     def code(self):
         return 'import platform; print(platform.dist())'
 
-    def codename(self):
+    def os_codename(self):
         distname, version, id = self.exe()
 
         patterns = [
                 return name
 
     def do(self):
-        codename = self.codename()
-        if codename is None:
+        os_codename = self.os_codename()
+        if os_codename is None:
             abort('Your OS is unsupported')
             return
-        puts('OS codename: %s' % codename)
+        puts('OS codename: %s' % os_codename)
 
 os_codename = OSCodename()
 

File tests/test_containers.py

 from fabdeploy.containers import BaseConf, conf
 
 
-class MyTask(Task):
-    @conf
-    def foo(self):
-        return 'obj'
+def test_set_get():
+    c = BaseConf()
+    c.foo = 'data'
+    assert c.foo == 'data'
 
 
-def test_set_get():
-    d = BaseConf()
-    d.foo = 'data'
-    assert d.foo == 'data'
+def test_get_from_task():
+    class MyTask(Task):
+        @conf
+        def foo(self):
+            return 'task'
 
-    d = BaseConf(task=MyTask())
-    d.foo = 'data'
-    assert d.foo == 'obj'
+    c = BaseConf(tasks=[MyTask()])
+    c.foo = 'user'
+    assert c.foo == 'task'
 
-    d.setdefault('foo', 'bla')
-    assert d.foo == 'obj'
+    c.setdefault('foo', 'bla')
+    assert c.foo == 'task'
 
-    d.setdefault('bla', 'bla')
-    assert d.bla == 'bla'
+    c.setdefault('bar', 'default')
+    assert c.bar == 'default'
 
-    assert d.get('not_exist', 'default') == 'default'
+    assert c.get('not_exist', 'default') == 'default'
+
+
+def test_get_from_multiple_tasks():
+    class Task1(Task):
+        @conf
+        def foo(self):
+            return 'task1'
+
+    class Task2(Task):
+        @conf
+        def foo(self):
+            return 'task1'
+
+    c = BaseConf(tasks=[Task1(), Task2()])
+    assert c.foo == 'task1'
+
+
+def test_set_conf_value():
+    class MyConf(BaseConf):
+        user_value = 'user'
+
+    c = MyConf()
+    c.set_conf_value('user_value', 'my', keep_user_value=True)
+    assert c.user_value == 'user'
 
 
 def test_jinja2_usage():
-    d = BaseConf(task=MyTask())
-    d.foo = 'data'
+    class MyConf(BaseConf):
+        foo = 'bar'
 
     template = Template('{{ foo }}')
-    value = template.render(**d)
-    assert value == u'obj'
+    value = template.render(**MyConf())
+    assert value == u'bar'

File tests/test_default_conf.py

 def test_update_conf():
     conf = DefaultConf()
     conf.address = 'fabdeploy@localhost'
-    conf.os = None
 
     assert conf.user == 'fabdeploy'
     assert conf.host == 'localhost'
     assert conf.instance_name == 'fabdeploy'
 
     assert conf.home_path == '/home/fabdeploy'
+    assert conf.fabdeploy_path == '/home/fabdeploy/.fabdeploy.d'
+    assert conf.fabdeploy_bin_path == conf.fabdeploy_path + '/bin'
     assert conf.version_path == '/home/fabdeploy/%s' % conf.version
     assert conf.src_path == conf.version_path + '/src'
     assert conf.project_path == conf.version_path + '/src'

File tests/test_execute_task.py

 from fabdeploy.task import Task
 
 
-class HelloTask(Task):
-    def do(self):
-        return run("""python -c "print 'Hello'" """)
+def test_execute_task():
+    class HelloTask(Task):
+        def do(self):
+            return run("""python -c "print 'Hello'" """)
 
-
-def test_execute_task():
     hello = HelloTask()
     with hello.tmp_conf(
-        {'address': 'vladimir@localhost',
-         'sudo_user': 'vladimir'},
+        {'sudo_user': 'vladimir'},
         abort_on_prompts=True):
         output = hello.run()
     assert output == 'Hello'

File tests/test_system.py

+import multiprocessing
+
+from fabdeploy import system
+
+
+def test_cpu_count():
+    cpu_count = multiprocessing.cpu_count()
+    with system.cpu_count.tmp_conf():
+        assert system.cpu_count.cpu_count() == cpu_count
+
+
+def test_os_codename():
+    with system.os_codename.tmp_conf():
+        assert system.os_codename.os_codename() != None

File tests/test_task.py

 
 
 @with_setup(setup, teardown)
-def test_example_task_defaults():
-    r = example_task.run()
-    assert r == ['cls', 'def', 'def', 'def']
+def test_task_has_access_to_env_conf():
+    class MyTask(Task):
+        pass
+    my_task = MyTask()
+
+    env.conf.foo = 'env'
+    with my_task.tmp_conf():
+        assert my_task.conf.foo == 'env'
 
 
 @with_setup(setup, teardown)
-def test_example_task_with_env():
-    env.conf.var2 = 'env'
-    r = example_task.run(var3='kwarg')
-    assert r == ['cls', 'env', 'kwarg', 'def']
+def test_task_has_access_to_kwargs():
+    class MyTask(Task):
+        pass
+    my_task = MyTask()
 
-
-@with_setup(setup, teardown)
-def test_example_task_with_kwargs():
-    r = example_task.run(
-        var1='kwarg',
-        var2='kwarg',
-        var3='kwarg',
-        var4='kwarg')
-    assert r == ['kwarg', 'kwarg', 'kwarg', 'kwarg']
-
-
-class Task1(Task):
-    @conf
-    def var(self):
-        return 'task1'
-
-    def do(self):
-        print self.task_kwargs
-        return self.conf.var
-
-task1 = Task1()
+    with my_task.tmp_conf(task_kwargs={'foo': 'kwarg'}):
+        assert my_task.conf.foo == 'kwarg'
 
 
 @with_setup(setup, teardown)
 def test_task_called_with_conf_of_another_task():
+    class Task1(Task):
+        @conf
+        def var(self):
+            return 'task1'
+    task1 = Task1()
+
     class Task0(Task):
         def do(self):
             with task1.tmp_conf(self.conf):
-                return task1.run()
+                assert task1.conf.bar == 'task0'
 
     task0 = Task0()
-
-    assert task0.run(var='foo') == 'foo'
-
-
-@with_setup(setup, teardown)
-def test_task_called_from_another_task():
-    class Task0(Task):
-        def do(self):
-            return task1.run(var='bar')
-
-    task0 = Task0()
-
-    assert task0.run(var='foo') == 'bar'
-
-
-@with_setup(setup, teardown)
-def test_task_with_different_configs():
-    class Task0(Task):
-        def do(self):
-            with task1.tmp_conf({'var': 'task4'}):
-                print task1.task_kwargs
-                v1 = task1.run()
-            return v1, self.conf.var
-
-    task0 = Task0()
-
-    r = task0.run(var='foo')
-    assert r == ('task4', 'foo')
-
-
-@with_setup(setup, teardown)
-def test_setting_conf_in_task():
-    class Task0(Task):
-        def do(self):
-            with task1.tmp_conf(self.conf):
-                self.conf.foo = 'bar'
-            return self.conf.foo
-
-    task0 = Task0()
-
-    r = task0.run()
-    assert r == 'bar'
+    task0.run(bar='task0')