X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fceph-volume%2Fceph_volume%2Ftests%2Ftest_decorators.py;fp=src%2Fceph%2Fsrc%2Fceph-volume%2Fceph_volume%2Ftests%2Ftest_decorators.py;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=8df891456e607afc2960b60128449b3eb067bcec;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/ceph-volume/ceph_volume/tests/test_decorators.py b/src/ceph/src/ceph-volume/ceph_volume/tests/test_decorators.py deleted file mode 100644 index 8df8914..0000000 --- a/src/ceph/src/ceph-volume/ceph_volume/tests/test_decorators.py +++ /dev/null @@ -1,71 +0,0 @@ -import os -import pytest -from ceph_volume import exceptions, decorators, terminal - - -class TestNeedsRoot(object): - - def test_is_root(self, monkeypatch): - def func(): - return True - monkeypatch.setattr(decorators.os, 'getuid', lambda: 0) - assert decorators.needs_root(func)() is True - - def test_is_not_root(self, monkeypatch): - def func(): - return True # pragma: no cover - monkeypatch.setattr(decorators.os, 'getuid', lambda: 20) - with pytest.raises(exceptions.SuperUserError) as error: - decorators.needs_root(func)() - - msg = 'This command needs to be executed with sudo or as root' - assert str(error.value) == msg - - -class TestExceptionMessage(object): - - def test_has_str_method(self): - result = decorators.make_exception_message(RuntimeError('an error')) - expected = "%s %s\n" % (terminal.red_arrow, 'RuntimeError: an error') - assert result == expected - - def test_has_no_str_method(self): - class Error(Exception): - pass - result = decorators.make_exception_message(Error()) - expected = "%s %s\n" % (terminal.red_arrow, 'Error') - assert result == expected - - -class TestCatches(object): - - def teardown(self): - try: - del(os.environ['CEPH_VOLUME_DEBUG']) - except KeyError: - pass - - def test_ceph_volume_debug_enabled(self): - os.environ['CEPH_VOLUME_DEBUG'] = '1' - @decorators.catches() # noqa - def func(): - raise RuntimeError() - with pytest.raises(RuntimeError): - func() - - def test_ceph_volume_debug_disabled_no_exit(self, capsys): - @decorators.catches(exit=False) - def func(): - raise RuntimeError() - func() - stdout, stderr = capsys.readouterr() - assert 'RuntimeError\n' in stderr - - def test_ceph_volume_debug_exits(self, capsys): - @decorators.catches() - def func(): - raise RuntimeError() - with pytest.raises(SystemExit): - func() - stdout, stderr = capsys.readouterr() - assert 'RuntimeError\n' in stderr