]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Port from nosetests to py.test
authorZack Cerza <zack@cerza.org>
Mon, 30 Sep 2013 18:30:28 +0000 (13:30 -0500)
committerZack Cerza <zack@cerza.org>
Tue, 1 Oct 2013 14:07:45 +0000 (09:07 -0500)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/test/test_cluster.py
teuthology/orchestra/test/test_connection.py
teuthology/orchestra/test/test_integration.py
teuthology/orchestra/test/test_remote.py
teuthology/orchestra/test/test_run.py
teuthology/test/test_misc.py
teuthology/test/test_safepath.py

index 0616fc2d9bbd663b5ae7399890d015f40d13dc31..fad078b10a5d551dc543726db67ac2ccc7349ae1 100644 (file)
-from nose.tools import eq_ as eq
-
 import fudge
-import nose
 
 from .. import cluster, remote
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_init_empty():
-    c = cluster.Cluster()
-    eq(c.remotes, {})
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_init():
-    r1 = fudge.Fake('Remote')
-    r2 = fudge.Fake('Remote')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['baz']),
-            ],
-        )
-    r3 = fudge.Fake('Remote')
-    c.add(r3, ['xyzzy', 'thud', 'foo'])
-    eq(c.remotes, {
+class TestCluster(object):
+    @fudge.with_fakes
+    def test_init_empty(self):
+        fudge.clear_expectations()
+        c = cluster.Cluster()
+        assert c.remotes == {}
+
+    @fudge.with_fakes
+    def test_init(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('Remote')
+        r2 = fudge.Fake('Remote')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['baz']),
+                ],
+            )
+        r3 = fudge.Fake('Remote')
+        c.add(r3, ['xyzzy', 'thud', 'foo'])
+        assert c.remotes == {
             r1: ['foo', 'bar'],
             r2: ['baz'],
             r3: ['xyzzy', 'thud', 'foo'],
-            })
+        }
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_repr():
-    r1 = remote.Remote('r1', ssh=fudge.Fake('SSH'))
-    r2 = remote.Remote('r2', ssh=fudge.Fake('SSH'))
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['baz']),
-            ],
-        )
-    eq(repr(c), "Cluster(remotes={Remote(name='r1'): ['foo', 'bar'], Remote(name='r2'): ['baz']})")
+    @fudge.with_fakes
+    def test_repr(self):
+        fudge.clear_expectations()
+        r1 = remote.Remote('r1', ssh=fudge.Fake('SSH'))
+        r2 = remote.Remote('r2', ssh=fudge.Fake('SSH'))
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['baz']),
+                ],
+            )
+        assert repr(c) == "Cluster(remotes={Remote(name='r1'): ['foo', 'bar'], Remote(name='r2'): ['baz']})" # noqa
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_str():
-    r1 = remote.Remote('r1', ssh=fudge.Fake('SSH'))
-    r2 = remote.Remote('r2', ssh=fudge.Fake('SSH'))
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['baz']),
-            ],
-        )
-    eq(str(c), "r1[foo,bar] r2[baz]")
+    @fudge.with_fakes
+    def test_str(self):
+        fudge.clear_expectations()
+        r1 = remote.Remote('r1', ssh=fudge.Fake('SSH'))
+        r2 = remote.Remote('r2', ssh=fudge.Fake('SSH'))
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['baz']),
+                ],
+            )
+        assert str(c) == "r1[foo,bar] r2[baz]"
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_all():
-    r1 = fudge.Fake('Remote').has_attr(name='r1')
-    ret1 = fudge.Fake('RemoteProcess')
-    r1.expects('run').with_args(args=['test']).returns(ret1)
-    r2 = fudge.Fake('Remote').has_attr(name='r2')
-    ret2 = fudge.Fake('RemoteProcess')
-    r2.expects('run').with_args(args=['test']).returns(ret2)
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['baz']),
-            ],
-        )
-    got = c.run(args=['test'])
-    eq(len(got), 2)
-    eq(got, [ret1, ret2])
-    # check identity not equality
-    assert got[0] is ret1
-    assert got[1] is ret2
+    @fudge.with_fakes
+    def test_run_all(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('Remote').has_attr(name='r1')
+        ret1 = fudge.Fake('RemoteProcess')
+        r1.expects('run').with_args(args=['test']).returns(ret1)
+        r2 = fudge.Fake('Remote').has_attr(name='r2')
+        ret2 = fudge.Fake('RemoteProcess')
+        r2.expects('run').with_args(args=['test']).returns(ret2)
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['baz']),
+                ],
+            )
+        got = c.run(args=['test'])
+        assert len(got) == 2
+        assert got, [ret1 == ret2]
+        # check identity not equality
+        assert got[0] is ret1
+        assert got[1] is ret2
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_only_one():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_foo = c.only('foo')
-    eq(c_foo.remotes, {r1: ['foo', 'bar'], r3: ['foo']})
+    @fudge.with_fakes
+    def test_only_one(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_foo = c.only('foo')
+        assert c_foo.remotes == {r1: ['foo', 'bar'], r3: ['foo']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_only_two():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_both = c.only('foo', 'bar')
-    eq(c_both.remotes, {r1: ['foo', 'bar']})
+    @fudge.with_fakes
+    def test_only_two(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_both = c.only('foo', 'bar')
+        assert c_both.remotes, {r1: ['foo' == 'bar']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_only_none():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_none = c.only('impossible')
-    eq(c_none.remotes, {})
+    @fudge.with_fakes
+    def test_only_none(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_none = c.only('impossible')
+        assert c_none.remotes == {}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_only_match():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_foo = c.only('foo', lambda role: role.startswith('b'))
-    eq(c_foo.remotes, {r1: ['foo', 'bar']})
+    @fudge.with_fakes
+    def test_only_match(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_foo = c.only('foo', lambda role: role.startswith('b'))
+        assert c_foo.remotes, {r1: ['foo' == 'bar']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_exclude_one():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_foo = c.exclude('foo')
-    eq(c_foo.remotes, {r2: ['bar']})
+    @fudge.with_fakes
+    def test_exclude_one(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_foo = c.exclude('foo')
+        assert c_foo.remotes == {r2: ['bar']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_exclude_two():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_both = c.exclude('foo', 'bar')
-    eq(c_both.remotes, {r2: ['bar'], r3: ['foo']})
+    @fudge.with_fakes
+    def test_exclude_two(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_both = c.exclude('foo', 'bar')
+        assert c_both.remotes == {r2: ['bar'], r3: ['foo']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_exclude_none():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_none = c.exclude('impossible')
-    eq(c_none.remotes, {r1: ['foo', 'bar'], r2: ['bar'], r3: ['foo']})
+    @fudge.with_fakes
+    def test_exclude_none(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_none = c.exclude('impossible')
+        assert c_none.remotes == {r1: ['foo', 'bar'], r2: ['bar'], r3: ['foo']}
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_exclude_match():
-    r1 = fudge.Fake('r1')
-    r2 = fudge.Fake('r2')
-    r3 = fudge.Fake('r3')
-    c = cluster.Cluster(
-        remotes=[
-            (r1, ['foo', 'bar']),
-            (r2, ['bar']),
-            (r3, ['foo']),
-            ],
-        )
-    c_foo = c.exclude('foo', lambda role: role.startswith('b'))
-    eq(c_foo.remotes, {r2: ['bar'], r3: ['foo']})
+    @fudge.with_fakes
+    def test_exclude_match(self):
+        fudge.clear_expectations()
+        r1 = fudge.Fake('r1')
+        r2 = fudge.Fake('r2')
+        r3 = fudge.Fake('r3')
+        c = cluster.Cluster(
+            remotes=[
+                (r1, ['foo', 'bar']),
+                (r2, ['bar']),
+                (r3, ['foo']),
+                ],
+            )
+        c_foo = c.exclude('foo', lambda role: role.startswith('b'))
+        assert c_foo.remotes == {r2: ['bar'], r3: ['foo']}
index 32146190a3c298b1379accb79cf136f1daa41f69..550a43572c8473016af0688e78aa3bf20f3afc9c 100644 (file)
@@ -1,77 +1,81 @@
-from nose.tools import eq_ as eq
+from teuthology import config
 
 import fudge
-import nose
 
 from .util import assert_raises
 
 from .. import connection
 
 
-def test_split_user_just_host():
-    got = connection.split_user('somehost.example.com')
-    eq(got, (None, 'somehost.example.com'))
+class TestConnection(object):
+    def clear_config(self):
+        config.config.teuthology_yaml = ''
+        config.config.load_files()
 
+    def test_split_user_just_host(self):
+        got = connection.split_user('somehost.example.com')
+        assert got == (None, 'somehost.example.com')
 
-def test_split_user_both():
-    got = connection.split_user('jdoe@somehost.example.com')
-    eq(got, ('jdoe', 'somehost.example.com'))
+    def test_split_user_both(self):
+        got = connection.split_user('jdoe@somehost.example.com')
+        assert got == ('jdoe', 'somehost.example.com')
 
+    def test_split_user_empty_user(self):
+        s = '@somehost.example.com'
+        e = assert_raises(AssertionError, connection.split_user, s)
+        assert str(e) == 'Bad input to split_user: {s!r}'.format(s=s)
 
-def test_split_user_empty_user():
-    s = '@somehost.example.com'
-    e = assert_raises(AssertionError, connection.split_user, s)
-    eq(str(e), 'Bad input to split_user: {s!r}'.format(s=s))
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_connect():
-    ssh = fudge.Fake('SSHClient')
-    ssh.expects_call().with_args().returns(ssh)
-    ssh.expects('set_missing_host_key_policy')
-    ssh.expects('load_system_host_keys').with_args()
-    ssh.expects('connect').with_args(
-        hostname='orchestra.test.newdream.net.invalid',
-        username='jdoe',
-        timeout=60,
-    )
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.remember_order()
-    transport.expects('set_keepalive').with_args(False)
-    got = connection.connect(
-        'jdoe@orchestra.test.newdream.net.invalid',
-        _SSHClient=ssh,
-    )
-    assert got is ssh
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_connect_override_hostkeys():
-    sshclient = fudge.Fake('SSHClient')
-    ssh = sshclient.expects_call().with_args().returns_fake()
-    ssh.remember_order()
-    host_keys = fudge.Fake('HostKeys')
-    host_keys.expects('add').with_args(
-        hostname='orchestra.test.newdream.net.invalid',
-        keytype='ssh-rsa',
-        key='frobnitz',
+    @fudge.with_fakes
+    def test_connect(self):
+        self.clear_config()
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHClient')
+        ssh.expects_call().with_args().returns(ssh)
+        ssh.expects('set_missing_host_key_policy')
+        ssh.expects('load_system_host_keys').with_args()
+        ssh.expects('connect').with_args(
+            hostname='orchestra.test.newdream.net.invalid',
+            username='jdoe',
+            timeout=60,
         )
-    ssh.expects('get_host_keys').with_args().returns(host_keys)
-    ssh.expects('connect').with_args(
-        hostname='orchestra.test.newdream.net.invalid',
-        username='jdoe',
-        timeout=60,
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.remember_order()
+        transport.expects('set_keepalive').with_args(False)
+        got = connection.connect(
+            'jdoe@orchestra.test.newdream.net.invalid',
+            _SSHClient=ssh,
         )
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.remember_order()
-    transport.expects('set_keepalive').with_args(False)
-    create_key = fudge.Fake('create_key')
-    create_key.expects_call().with_args('ssh-rsa', 'testkey').returns('frobnitz')
-    got = connection.connect(
-        'jdoe@orchestra.test.newdream.net.invalid',
-        host_key='ssh-rsa testkey',
-        _SSHClient=sshclient,
-        _create_key=create_key,
-        )
-    assert got is ssh
+        assert got is ssh
+
+    @fudge.with_fakes
+    def test_connect_override_hostkeys(self):
+        self.clear_config()
+        fudge.clear_expectations()
+        sshclient = fudge.Fake('SSHClient')
+        ssh = sshclient.expects_call().with_args().returns_fake()
+        ssh.remember_order()
+        host_keys = fudge.Fake('HostKeys')
+        host_keys.expects('add').with_args(
+            hostname='orchestra.test.newdream.net.invalid',
+            keytype='ssh-rsa',
+            key='frobnitz',
+            )
+        ssh.expects('get_host_keys').with_args().returns(host_keys)
+        ssh.expects('connect').with_args(
+            hostname='orchestra.test.newdream.net.invalid',
+            username='jdoe',
+            timeout=60,
+            )
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.remember_order()
+        transport.expects('set_keepalive').with_args(False)
+        create_key = fudge.Fake('create_key')
+        create_key.expects_call().with_args('ssh-rsa',
+                                            'testkey').returns('frobnitz')
+        got = connection.connect(
+            'jdoe@orchestra.test.newdream.net.invalid',
+            host_key='ssh-rsa testkey',
+            _SSHClient=sshclient,
+            _create_key=create_key,
+            )
+        assert got is ssh
index 39e15fc4b86b7cfa22439630a1fb88aad186fe27..03aa962ad9b719ffd529f6710440edb291c3bafc 100644 (file)
@@ -1,73 +1,73 @@
-from .. import monkey; monkey.patch_all()
+from .. import monkey
+monkey.patch_all()
 
-from nose.tools import eq_ as eq
 from cStringIO import StringIO
 
 import os
-import nose
-
 from .. import connection, run
-
 from .util import assert_raises
 
+from pytest import skip
+
 HOST = None
 
-def setup():
-    try:
-        host = os.environ['ORCHESTRA_TEST_HOST']
-    except KeyError:
-        raise nose.SkipTest(
-            'To run integration tests, set environment '
-            + 'variable ORCHESTRA_TEST_HOST to user@host to use.',
-            )
-    global HOST
-    HOST = host
 
-def test_crash():
-    ssh = connection.connect(HOST)
-    e = assert_raises(
-        run.CommandCrashedError,
-        run.run,
-        client=ssh,
-        args=['sh', '-c', 'kill -ABRT $$'],
-        )
-    eq(e.command, "sh -c 'kill -ABRT $$'")
-    eq(str(e), "Command crashed: \"sh -c 'kill -ABRT $$'\"")
+class TestIntegration():
+    def setup(self):
+        try:
+            host = os.environ['ORCHESTRA_TEST_HOST']
+        except KeyError:
+            skip('To run integration tests, set environment ' +
+                 'variable ORCHESTRA_TEST_HOST to user@host to use.')
+        global HOST
+        HOST = host
 
-def test_lost():
-    ssh = connection.connect(HOST)
-    e = assert_raises(
-        run.ConnectionLostError,
-        run.run,
-        client=ssh,
-        args=['sh', '-c', 'kill -ABRT $PPID'],
-        )
-    eq(e.command, "sh -c 'kill -ABRT $PPID'")
-    eq(str(e), "SSH connection was lost: \"sh -c 'kill -ABRT $PPID'\"")
+    def test_crash(self):
+        ssh = connection.connect(HOST)
+        e = assert_raises(
+            run.CommandCrashedError,
+            run.run,
+            client=ssh,
+            args=['sh', '-c', 'kill -ABRT $$'],
+            )
+        assert e.command == "sh -c 'kill -ABRT $$'"
+        assert str(e) == "Command crashed: \"sh -c 'kill -ABRT $$'\""
 
-def test_pipe():
-    ssh = connection.connect(HOST)
-    r = run.run(
-        client=ssh,
-        args=['cat'],
-        stdin=run.PIPE,
-        stdout=StringIO(),
-        wait=False,
-        )
-    eq(r.stdout.getvalue(), '')
-    r.stdin.write('foo\n')
-    r.stdin.write('bar\n')
-    r.stdin.close()
+    def test_lost(self):
+        ssh = connection.connect(HOST)
+        e = assert_raises(
+            run.ConnectionLostError,
+            run.run,
+            client=ssh,
+            args=['sh', '-c', 'kill -ABRT $PPID'],
+            )
+        assert e.command == "sh -c 'kill -ABRT $PPID'"
+        assert str(e) == \
+            "SSH connection was lost: \"sh -c 'kill -ABRT $PPID'\""
+
+    def test_pipe(self):
+        ssh = connection.connect(HOST)
+        r = run.run(
+            client=ssh,
+            args=['cat'],
+            stdin=run.PIPE,
+            stdout=StringIO(),
+            wait=False,
+            )
+        assert r.stdout.getvalue() == ''
+        r.stdin.write('foo\n')
+        r.stdin.write('bar\n')
+        r.stdin.close()
 
-    got = r.exitstatus.get()
-    eq(got, 0)
-    eq(r.stdout.getvalue(), 'foo\nbar\n')
+        got = r.exitstatus.get()
+        assert got == 0
+        assert r.stdout.getvalue() == 'foo\nbar\n'
 
-def test_and():
-    ssh = connection.connect(HOST)
-    r = run.run(
-        client=ssh,
-        args=['true', run.Raw('&&'), 'echo', 'yup'],
-        stdout=StringIO(),
-        )
-    eq(r.stdout.getvalue(), 'yup\n')
+    def test_and(self):
+        ssh = connection.connect(HOST)
+        r = run.run(
+            client=ssh,
+            args=['true', run.Raw('&&'), 'echo', 'yup'],
+            stdout=StringIO(),
+            )
+        assert r.stdout.getvalue() == 'yup\n'
index 3b19f594acea62353574f75d6b62461670dcb744..dbff6ffc42f9c62f98ae500510477c44f27b0fc6 100644 (file)
@@ -1,61 +1,57 @@
-from nose.tools import eq_ as eq
-
 import fudge
 import fudge.inspector
-import nose
 
 from .. import remote
 from ..run import RemoteProcess
 
 
-def test_shortname():
-    r = remote.Remote(
-        name='jdoe@xyzzy.example.com',
-        shortname='xyz',
-        ssh=fudge.Fake('SSHConnection'),
-        )
-    eq(r.shortname, 'xyz')
-    eq(str(r), 'xyz')
-
-
-def test_shortname_default():
-    r = remote.Remote(
-        name='jdoe@xyzzy.example.com',
-        ssh=fudge.Fake('SSHConnection'),
-        )
-    eq(r.shortname, 'jdoe@xyzzy.example.com')
-    eq(str(r), 'jdoe@xyzzy.example.com')
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run():
-    ssh = fudge.Fake('SSHConnection')
-    run = fudge.Fake('run')
-    args = [
-        'something',
-        'more',
-        ]
-    foo = object()
-    ret = RemoteProcess(
-        command='fakey',
-        stdin=None,
-        stdout=None,
-        stderr=None,
-        exitstatus=None,
-        exited=None,
-        )
-    run.expects_call().with_args(
-        client=fudge.inspector.arg.passes_test(lambda v: v is ssh),
-        args=fudge.inspector.arg.passes_test(lambda v: v is args),
-        foo=fudge.inspector.arg.passes_test(lambda v: v is foo),
-        ).returns(ret)
-    r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh)
-    # monkey patch ook ook
-    r._runner = run
-    got = r.run(
-        args=args,
-        foo=foo,
-        )
-    assert got is ret
-    assert got.remote is r
+class TestRemote(object):
+    def test_shortname(self):
+        r = remote.Remote(
+            name='jdoe@xyzzy.example.com',
+            shortname='xyz',
+            ssh=fudge.Fake('SSHConnection'),
+            )
+        assert r.shortname == 'xyz'
+        assert str(r) == 'xyz'
+
+    def test_shortname_default(self):
+        r = remote.Remote(
+            name='jdoe@xyzzy.example.com',
+            ssh=fudge.Fake('SSHConnection'),
+            )
+        assert r.shortname == 'jdoe@xyzzy.example.com'
+        assert str(r) == 'jdoe@xyzzy.example.com'
+
+    @fudge.with_fakes
+    def test_run(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        run = fudge.Fake('run')
+        args = [
+            'something',
+            'more',
+            ]
+        foo = object()
+        ret = RemoteProcess(
+            command='fakey',
+            stdin=None,
+            stdout=None,
+            stderr=None,
+            exitstatus=None,
+            exited=None,
+            )
+        run.expects_call().with_args(
+            client=fudge.inspector.arg.passes_test(lambda v: v is ssh),
+            args=fudge.inspector.arg.passes_test(lambda v: v is args),
+            foo=fudge.inspector.arg.passes_test(lambda v: v is foo),
+            ).returns(ret)
+        r = remote.Remote(name='jdoe@xyzzy.example.com', ssh=ssh)
+        # monkey patch ook ook
+        r._runner = run
+        got = r.run(
+            args=args,
+            foo=foo,
+            )
+        assert got is ret
+        assert got.remote is r
index 3614d883443ebafb184330eab1a4648094b6384b..96cee4417a3fff70f05b41cead54866a30db0024 100644 (file)
@@ -1,9 +1,7 @@
-from nose.tools import eq_ as eq
 from cStringIO import StringIO
 
 import fudge
 import gevent.event
-import nose
 import logging
 
 from .. import run
@@ -11,404 +9,394 @@ from .. import run
 from .util import assert_raises
 
 
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_log_simple():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo 'bar baz'")
-    in_ = fudge.Fake('ChannelFile(stdin)')
-    out = fudge.Fake('ChannelFile(stdout)')
-    err = fudge.Fake('ChannelFile(stderr)')
-    cmd.returns((in_, out, err))
-    in_.expects('close').with_args()
-    in_chan = fudge.Fake('channel')
-    in_chan.expects('shutdown_write').with_args()
-    in_.has_attr(channel=in_chan)
-    out.expects('xreadlines').with_args().returns(['foo', 'bar'])
-    err.expects('xreadlines').with_args().returns(['bad'])
-    logger = fudge.Fake('logger')
-    log_err = fudge.Fake('log_err')
-    logger.expects('getChild').with_args('err').returns(log_err)
-    log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
-    log_out = fudge.Fake('log_out')
-    logger.expects('getChild').with_args('out').returns(log_out)
-    log_out.expects('log').with_args(logging.INFO, '[HOST]: foo')
-    log_out.expects('log').with_args(logging.INFO, '[HOST]: bar')
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(0)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo', 'bar baz'],
-        )
-    eq(r.exitstatus, 0)
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_capture_stdout():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo 'bar baz'")
-    in_ = fudge.Fake('ChannelFile(stdin)')
-    out = fudge.Fake('ChannelFile(stdout)')
-    err = fudge.Fake('ChannelFile(stderr)')
-    cmd.returns((in_, out, err))
-    in_.expects('close').with_args()
-    in_chan = fudge.Fake('channel')
-    in_chan.expects('shutdown_write').with_args()
-    in_.has_attr(channel=in_chan)
-    out.remember_order()
-    out.expects('read').with_args().returns('foo\nb')
-    out.expects('read').with_args().returns('ar\n')
-    out.expects('read').with_args().returns('')
-    err.expects('xreadlines').with_args().returns(['bad'])
-    logger = fudge.Fake('logger')
-    log_err = fudge.Fake('log_err')
-    logger.expects('getChild').with_args('err').returns(log_err)
-    log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(0)
-    out_f = StringIO()
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo', 'bar baz'],
-        stdout=out_f,
-        )
-    eq(r.exitstatus, 0)
-    assert r.stdout is out_f
-    eq(r.stdout.getvalue(), 'foo\nbar\n')
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_bad():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(42)
-    e = assert_raises(
-        run.CommandFailedError,
-        run.run,
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        )
-    eq(e.command, 'foo')
-    eq(e.exitstatus, 42)
-    eq(str(e), "Command failed on HOST with status 42: 'foo'")
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_bad_nocheck():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(42)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        check_status=False,
-        )
-    eq(r.exitstatus, 42)
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_crash():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    transport.expects('is_active').with_args().returns(True)
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(-1)
-    e = assert_raises(
-        run.CommandCrashedError,
-        run.run,
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        )
-    eq(e.command, 'foo')
-    eq(str(e), "Command crashed: 'foo'")
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_crash_nocheck():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(-1)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        check_status=False,
-        )
-    assert r.exitstatus is None
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_lost():
-    ssh = fudge.Fake('SSHConnection')
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(-1)
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    transport.expects('is_active').with_args().returns(False)
-    e = assert_raises(
-        run.ConnectionLostError,
-        run.run,
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        )
-
-    eq(e.command, 'foo')
-    eq(str(e), "SSH connection was lost: 'foo'")
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_status_lost_nocheck():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(-1)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        check_status=False,
-        )
-    assert r.exitstatus is None
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_nowait():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(42)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        wait=False,
-        )
-    eq(r.command, 'foo')
-    assert isinstance(r.exitstatus, gevent.event.AsyncResult)
-    e = assert_raises(
-        run.CommandFailedError,
-        r.exitstatus.get,
-        )
-    eq(e.exitstatus, 42)
-    eq(str(e), "Command failed on HOST with status 42: 'foo'")
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_stdin_pipe():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(0)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        stdin=run.PIPE,
-        wait=False,
-        )
-    r.stdin.write('bar')
-    eq(r.command, 'foo')
-    assert isinstance(r.exitstatus, gevent.event.AsyncResult)
-    eq(r.exitstatus.ready(), False)
-    got = r.exitstatus.get()
-    eq(got, 0)
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_stdout_pipe():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('read').with_args().returns('one')
-    out.expects('read').with_args().returns('two')
-    out.expects('read').with_args().returns('')
-    err.expects('xreadlines').with_args().returns([])
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(0)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        stdout=run.PIPE,
-        wait=False,
-        )
-    eq(r.command, 'foo')
-    assert isinstance(r.exitstatus, gevent.event.AsyncResult)
-    eq(r.exitstatus.ready(), False)
-    eq(r.stdout.read(), 'one')
-    eq(r.stdout.read(), 'two')
-    eq(r.stdout.read(), '')
-    got = r.exitstatus.get()
-    eq(got, 0)
-
-
-@nose.with_setup(fudge.clear_expectations)
-@fudge.with_fakes
-def test_run_stderr_pipe():
-    ssh = fudge.Fake('SSHConnection')
-    transport = ssh.expects('get_transport').with_args().returns_fake()
-    transport.expects('getpeername').with_args().returns(('HOST', 22))
-    cmd = ssh.expects('exec_command')
-    cmd.with_args("foo")
-    in_ = fudge.Fake('ChannelFile').is_a_stub()
-    out = fudge.Fake('ChannelFile').is_a_stub()
-    err = fudge.Fake('ChannelFile').is_a_stub()
-    cmd.returns((in_, out, err))
-    out.expects('xreadlines').with_args().returns([])
-    err.expects('read').with_args().returns('one')
-    err.expects('read').with_args().returns('two')
-    err.expects('read').with_args().returns('')
-    logger = fudge.Fake('logger').is_a_stub()
-    channel = fudge.Fake('channel')
-    out.has_attr(channel=channel)
-    channel.expects('recv_exit_status').with_args().returns(0)
-    r = run.run(
-        client=ssh,
-        logger=logger,
-        args=['foo'],
-        stderr=run.PIPE,
-        wait=False,
-        )
-    eq(r.command, 'foo')
-    assert isinstance(r.exitstatus, gevent.event.AsyncResult)
-    eq(r.exitstatus.ready(), False)
-    eq(r.stderr.read(), 'one')
-    eq(r.stderr.read(), 'two')
-    eq(r.stderr.read(), '')
-    got = r.exitstatus.get()
-    eq(got, 0)
-
-
-def test_quote_simple():
-    got = run.quote(['a b', ' c', 'd e '])
-    eq(got, "'a b' ' c' 'd e '")
-
-def test_quote_and_quote():
-    got = run.quote(['echo', 'this && is embedded', '&&', 'that was standalone'])
-    eq(got, "echo 'this && is embedded' '&&' 'that was standalone'")
-
-def test_quote_and_raw():
-    got = run.quote(['true', run.Raw('&&'), 'echo', 'yay'])
-    eq(got, "true && echo yay")
+class TestRun(object):
+    @fudge.with_fakes
+    def test_run_log_simple(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo 'bar baz'")
+        in_ = fudge.Fake('ChannelFile(stdin)')
+        out = fudge.Fake('ChannelFile(stdout)')
+        err = fudge.Fake('ChannelFile(stderr)')
+        cmd.returns((in_, out, err))
+        in_.expects('close').with_args()
+        in_chan = fudge.Fake('channel')
+        in_chan.expects('shutdown_write').with_args()
+        in_.has_attr(channel=in_chan)
+        out.expects('xreadlines').with_args().returns(['foo', 'bar'])
+        err.expects('xreadlines').with_args().returns(['bad'])
+        logger = fudge.Fake('logger')
+        log_err = fudge.Fake('log_err')
+        logger.expects('getChild').with_args('err').returns(log_err)
+        log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
+        log_out = fudge.Fake('log_out')
+        logger.expects('getChild').with_args('out').returns(log_out)
+        log_out.expects('log').with_args(logging.INFO, '[HOST]: foo')
+        log_out.expects('log').with_args(logging.INFO, '[HOST]: bar')
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(0)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo', 'bar baz'],
+            )
+        assert r.exitstatus == 0
+
+    @fudge.with_fakes
+    def test_run_capture_stdout(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo 'bar baz'")
+        in_ = fudge.Fake('ChannelFile(stdin)')
+        out = fudge.Fake('ChannelFile(stdout)')
+        err = fudge.Fake('ChannelFile(stderr)')
+        cmd.returns((in_, out, err))
+        in_.expects('close').with_args()
+        in_chan = fudge.Fake('channel')
+        in_chan.expects('shutdown_write').with_args()
+        in_.has_attr(channel=in_chan)
+        out.remember_order()
+        out.expects('read').with_args().returns('foo\nb')
+        out.expects('read').with_args().returns('ar\n')
+        out.expects('read').with_args().returns('')
+        err.expects('xreadlines').with_args().returns(['bad'])
+        logger = fudge.Fake('logger')
+        log_err = fudge.Fake('log_err')
+        logger.expects('getChild').with_args('err').returns(log_err)
+        log_err.expects('log').with_args(logging.INFO, '[HOST]: bad')
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(0)
+        out_f = StringIO()
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo', 'bar baz'],
+            stdout=out_f,
+            )
+        assert r.exitstatus == 0
+        assert r.stdout is out_f
+        assert r.stdout.getvalue() == 'foo\nbar\n'
+
+    @fudge.with_fakes
+    def test_run_status_bad(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(42)
+        e = assert_raises(
+            run.CommandFailedError,
+            run.run,
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            )
+        assert e.command == 'foo'
+        assert e.exitstatus == 42
+        assert str(e) == "Command failed on HOST with status 42: 'foo'"
+
+    @fudge.with_fakes
+    def test_run_status_bad_nocheck(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(42)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            check_status=False,
+            )
+        assert r.exitstatus == 42
+
+    @fudge.with_fakes
+    def test_run_status_crash(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        transport.expects('is_active').with_args().returns(True)
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(-1)
+        e = assert_raises(
+            run.CommandCrashedError,
+            run.run,
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            )
+        assert e.command == 'foo'
+        assert str(e) == "Command crashed: 'foo'"
+
+    @fudge.with_fakes
+    def test_run_status_crash_nocheck(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(-1)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            check_status=False,
+            )
+        assert r.exitstatus is None
+
+    @fudge.with_fakes
+    def test_run_status_lost(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(-1)
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        transport.expects('is_active').with_args().returns(False)
+        e = assert_raises(
+            run.ConnectionLostError,
+            run.run,
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            )
+
+        assert e.command == 'foo'
+        assert str(e) == "SSH connection was lost: 'foo'"
+
+    @fudge.with_fakes
+    def test_run_status_lost_nocheck(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(-1)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            check_status=False,
+            )
+        assert r.exitstatus is None
+
+    @fudge.with_fakes
+    def test_run_nowait(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(42)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            wait=False,
+            )
+        assert r.command == 'foo'
+        assert isinstance(r.exitstatus, gevent.event.AsyncResult)
+        e = assert_raises(
+            run.CommandFailedError,
+            r.exitstatus.get,
+            )
+        assert e.exitstatus == 42
+        assert str(e) == "Command failed on HOST with status 42: 'foo'"
+
+    @fudge.with_fakes
+    def test_run_stdin_pipe(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(0)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            stdin=run.PIPE,
+            wait=False,
+            )
+        r.stdin.write('bar')
+        assert r.command == 'foo'
+        assert isinstance(r.exitstatus, gevent.event.AsyncResult)
+        assert r.exitstatus.ready() == False
+        got = r.exitstatus.get()
+        assert got == 0
+
+    @fudge.with_fakes
+    def test_run_stdout_pipe(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('read').with_args().returns('one')
+        out.expects('read').with_args().returns('two')
+        out.expects('read').with_args().returns('')
+        err.expects('xreadlines').with_args().returns([])
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(0)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            stdout=run.PIPE,
+            wait=False,
+            )
+        assert r.command == 'foo'
+        assert isinstance(r.exitstatus, gevent.event.AsyncResult)
+        assert r.exitstatus.ready() == False
+        assert r.stdout.read() == 'one'
+        assert r.stdout.read() == 'two'
+        assert r.stdout.read() == ''
+        got = r.exitstatus.get()
+        assert got == 0
+
+    @fudge.with_fakes
+    def test_run_stderr_pipe(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().returns(('HOST', 22))
+        cmd = ssh.expects('exec_command')
+        cmd.with_args("foo")
+        in_ = fudge.Fake('ChannelFile').is_a_stub()
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        err = fudge.Fake('ChannelFile').is_a_stub()
+        cmd.returns((in_, out, err))
+        out.expects('xreadlines').with_args().returns([])
+        err.expects('read').with_args().returns('one')
+        err.expects('read').with_args().returns('two')
+        err.expects('read').with_args().returns('')
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        channel.expects('recv_exit_status').with_args().returns(0)
+        r = run.run(
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            stderr=run.PIPE,
+            wait=False,
+            )
+        assert r.command == 'foo'
+        assert isinstance(r.exitstatus, gevent.event.AsyncResult)
+        assert r.exitstatus.ready() is False
+        assert r.stderr.read() == 'one'
+        assert r.stderr.read() == 'two'
+        assert r.stderr.read() == ''
+        got = r.exitstatus.get()
+        assert got == 0
+
+    def test_quote_simple(self):
+        got = run.quote(['a b', ' c', 'd e '])
+        assert got == "'a b' ' c' 'd e '"
+
+    def test_quote_and_quote(self):
+        got = run.quote(['echo', 'this && is embedded', '&&',
+                         'that was standalone'])
+        assert got == "echo 'this && is embedded' '&&' 'that was standalone'"
+
+    def test_quote_and_raw(self):
+        got = run.quote(['true', run.Raw('&&'), 'echo', 'yay'])
+        assert got == "true && echo yay"
index 1e71842fb9307bed223756454bee3b7d83715d47..b2919e64e97d9627288f392c43f6d3dff1e2182c 100644 (file)
@@ -1,15 +1,10 @@
 import argparse
 from ..orchestra import cluster
-
-from nose.tools import (
-    eq_ as eq,
-    assert_equal,
-    assert_raises,
-)
-
 from .. import misc
 from ..config import config
 
+import pytest
+
 
 class FakeRemote(object):
     pass
@@ -25,10 +20,11 @@ def test_get_clients_simple():
         )
     g = misc.get_clients(ctx=ctx, roles=['client.1'])
     got = next(g)
-    eq(len(got), 2)
-    eq(got[0], ('1'))
+    assert len(got) == 2
+    assert got[0] == ('1')
     assert got[1] is remote
-    assert_raises(StopIteration, next, g)
+    with pytest.raises(StopIteration):
+        next(g)
 
 
 def test_get_http_log_path():
@@ -38,11 +34,11 @@ def test_get_http_log_path():
     archive_dir = "/var/www/archives"
 
     path = misc.get_http_log_path(archive_dir)
-    assert_equal(path, "http://example.com/server_root/archives/")
+    assert path == "http://example.com/server_root/archives/"
 
     job_id = '12345'
     path = misc.get_http_log_path(archive_dir, job_id)
-    assert_equal(path, "http://example.com/server_root/archives/12345/")
+    assert path == "http://example.com/server_root/archives/12345/"
 
     # Inktank configuration
     archive_server = "http://qa-proxy.ceph.com/teuthology/"
@@ -50,7 +46,7 @@ def test_get_http_log_path():
     archive_dir = "/var/lib/teuthworker/archive/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps"
     job_id = 31087
     path = misc.get_http_log_path(archive_dir, job_id)
-    assert_equal(path, "http://qa-proxy.ceph.com/teuthology/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps/31087/")
+    assert path == "http://qa-proxy.ceph.com/teuthology/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps/31087/"
 
     path = misc.get_http_log_path(archive_dir)
-    assert_equal(path, "http://qa-proxy.ceph.com/teuthology/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps/")
+    assert path == "http://qa-proxy.ceph.com/teuthology/teuthology-2013-09-12_11:49:50-ceph-deploy-master-testing-basic-vps/"
index 4f05f10d2d70a3db7186c2e00578691ab99f04b2..e842e5a30c5a12e825820b249d45e41115102744 100644 (file)
@@ -1,56 +1,55 @@
-from nose.tools import eq_ as eq
-
 from .. import safepath
 
-def test_simple():
-    got = safepath.munge('foo')
-    eq(got, 'foo')
+class TestSafepath(object):
+    def test_simple(self):
+        got = safepath.munge('foo')
+        assert got == 'foo'
 
-def test_empty():
-    # really odd corner case
-    got = safepath.munge('')
-    eq(got, '_')
+    def test_empty(self):
+        # really odd corner case
+        got = safepath.munge('')
+        assert got == '_'
 
-def test_slash():
-    got = safepath.munge('/')
-    eq(got, '_')
+    def test_slash(self):
+        got = safepath.munge('/')
+        assert got == '_'
 
-def test_slashslash():
-    got = safepath.munge('//')
-    eq(got, '_')
+    def test_slashslash(self):
+        got = safepath.munge('//')
+        assert got == '_'
 
-def test_absolute():
-    got = safepath.munge('/evil')
-    eq(got, 'evil')
+    def test_absolute(self):
+        got = safepath.munge('/evil')
+        assert got == 'evil'
 
-def test_absolute_subdir():
-    got = safepath.munge('/evil/here')
-    eq(got, 'evil/here')
+    def test_absolute_subdir(self):
+        got = safepath.munge('/evil/here')
+        assert got == 'evil/here'
 
-def test_dot_leading():
-    got = safepath.munge('./foo')
-    eq(got, 'foo')
+    def test_dot_leading(self):
+        got = safepath.munge('./foo')
+        assert got == 'foo'
 
-def test_dot_middle():
-    got = safepath.munge('evil/./foo')
-    eq(got, 'evil/foo')
+    def test_dot_middle(self):
+        got = safepath.munge('evil/./foo')
+        assert got == 'evil/foo'
 
-def test_dot_trailing():
-    got = safepath.munge('evil/foo/.')
-    eq(got, 'evil/foo')
+    def test_dot_trailing(self):
+        got = safepath.munge('evil/foo/.')
+        assert got == 'evil/foo'
 
-def test_dotdot():
-    got = safepath.munge('../evil/foo')
-    eq(got, '_./evil/foo')
+    def test_dotdot(self):
+        got = safepath.munge('../evil/foo')
+        assert got == '_./evil/foo'
 
-def test_dotdot_subdir():
-    got = safepath.munge('evil/../foo')
-    eq(got, 'evil/_./foo')
+    def test_dotdot_subdir(self):
+        got = safepath.munge('evil/../foo')
+        assert got == 'evil/_./foo'
 
-def test_hidden():
-    got = safepath.munge('.evil')
-    eq(got, '_evil')
+    def test_hidden(self):
+        got = safepath.munge('.evil')
+        assert got == '_evil'
 
-def test_hidden_subdir():
-    got = safepath.munge('foo/.evil')
-    eq(got, 'foo/_evil')
+    def test_hidden_subdir(self):
+        got = safepath.munge('foo/.evil')
+        assert got == 'foo/_evil'