tests: utilize ok_() and eq_() from nose tools
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Dec 2013 08:19:34 +0000 (10:19 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 9 Dec 2013 15:05:37 +0000 (17:05 +0200)
In order to getter better assert messages.

Change-Id: Ibb57a3d2f71884e63e0f9294f26eb1b38e32d962
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tests/test_gbp_repocache.py
tests/test_obs_service_gbp.py

index 12e4c1b61d26bb1020589ba1069ddcf6a0944fb4..8af2445d5c4a2b0dbc39c8baee3ad574f047d178 100644 (file)
@@ -21,7 +21,7 @@
 import os
 import shutil
 import stat
-from nose.tools import assert_raises # pylint: disable=E0611
+from nose.tools import assert_raises, eq_, ok_  # pylint: disable=E0611
 
 from gbp.git.repository import GitRepositoryError
 
@@ -39,7 +39,7 @@ class TestMirrorGitRepository(UnitTestsBase):
             repo.set_config('foo', 'bar')
         repo.set_config('foo.bar', 'baz')
         repo.set_config('foo.bar', 'bax', replace=True)
-        assert repo.get_config('foo.bar') == 'bax'
+        eq_(repo.get_config('foo.bar'), 'bax')
 
 
 class TestCachedRepo(UnitTestsBase):
@@ -68,8 +68,8 @@ class TestCachedRepo(UnitTestsBase):
         """Basic test for cloning and fetching"""
         # Clone
         repo = self.MockCachedRepo(self.orig_repo.path)
-        assert repo
-        assert repo.repo.bare is not True
+        ok_(repo)
+        ok_(repo.repo.bare is not True)
         sha = repo.repo.rev_parse('master')
         path = repo.repo.path
         del repo
@@ -77,19 +77,19 @@ class TestCachedRepo(UnitTestsBase):
         self.update_repository_file(self.orig_repo, 'foo.txt', 'more data\n')
         # Fetch
         repo = self.MockCachedRepo(self.orig_repo.path)
-        assert repo
-        assert path == repo.repo.path
-        assert sha != repo.repo.rev_parse('master')
+        ok_(repo)
+        eq_(path, repo.repo.path)
+        ok_(sha != repo.repo.rev_parse('master'))
 
     def test_update_working_copy(self):
         """Test update functionality"""
         repo = self.MockCachedRepo(self.orig_repo.path)
         # Check that the refs are mapped correctly
         sha = repo.update_working_copy('HEAD~1')
-        assert sha == self.orig_repo.rev_parse('HEAD~1')
+        eq_(sha, self.orig_repo.rev_parse('HEAD~1'))
         sha = self.orig_repo.rev_parse('HEAD')
-        assert sha == repo.update_working_copy('HEAD')
-        assert sha == repo.update_working_copy(sha)
+        eq_(sha, repo.update_working_copy('HEAD'))
+        eq_(sha, repo.update_working_copy(sha))
 
         with assert_raises(CachedRepoError):
             sha = repo.update_working_copy('foo/bar')
@@ -109,7 +109,7 @@ class TestCachedRepo(UnitTestsBase):
         # from orig HEAD
         self.orig_repo.set_branch('HEAD~1')
         repo = self.MockCachedRepo(self.orig_repo.path)
-        assert repo.update_working_copy(shas[0]) == shas[0]
+        eq_(repo.update_working_copy(shas[0]), shas[0])
 
     def test_update_bare(self):
         """Test update for bare repository"""
@@ -132,7 +132,7 @@ class TestCachedRepo(UnitTestsBase):
         with assert_raises(CachedRepoError):
             repo.update_working_copy('HEAD')
         # Test valid refs, too
-        assert repo.update_working_copy('master')
+        ok_(repo.update_working_copy('master'))
 
         # Reset orig repo to original state
         self.orig_repo.set_branch(orig_branch)
@@ -148,16 +148,16 @@ class TestCachedRepo(UnitTestsBase):
         del repo
         # Update and check status
         repo = self.MockCachedRepo(self.orig_repo.path)
-        assert repo.repo.rev_parse('HEAD')
+        ok_(repo.repo.rev_parse('HEAD'))
 
     def test_changing_repotype(self):
         """Test changing repo type from bare -> normal"""
         # Clone
         repo = self.MockCachedRepo(self.orig_repo.path, bare=True)
-        assert repo.repo.bare == True
+        eq_(repo.repo.bare, True)
         del repo
         repo = self.MockCachedRepo(self.orig_repo.path, bare=False)
-        assert repo.repo.bare == False
+        eq_(repo.repo.bare, False)
 
     def test_cache_access_error(self):
         """Test cached directory with invalid permissions"""
index 5110700454da3ec2f828de8783763ea7ff5d5f3f..76ee6be2e44c1e3e69cc0f26264f5cfed5b7c9ea 100644 (file)
@@ -21,7 +21,7 @@
 import grp
 import os
 import stat
-from nose.tools import assert_raises # pylint: disable=E0611
+from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611
 
 from obs_service_gbp.command import main as service
 from tests import UnitTestsBase
@@ -35,7 +35,7 @@ class TestService(UnitTestsBase):
         """Check that the tmpdir content matches expectations"""
         found = set(os.listdir(os.path.join(self.tmpdir, directory)))
         expect = set(files)
-        assert found == expect, "Expected: %s, Found: %s" % (expect, found)
+        eq_(found, expect, "Expected: %s, Found: %s" % (expect, found))
 
     def test_invalid_options(self):
         """Test invalid options"""
@@ -44,31 +44,30 @@ class TestService(UnitTestsBase):
             service(['--foo'])
         # Option without argument
         with assert_raises(SystemExit):
-            assert service(['--url'])
+            ok_(service(['--url']))
         # Invalid repo
-        assert service(['--url=foo/bar.git']) != 0
+        ok_(service(['--url=foo/bar.git']) != 0)
 
     def test_basic_rpm_export(self):
         """Test that rpm export works"""
-        assert service(['--url', self.orig_repo.path, '--revision=rpm']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--revision=rpm']), 0)
         self._check_files(['test-package.spec', 'test-package_0.1.tar.gz'])
 
     def test_basic_deb_export(self):
         """Test that deb export works"""
-        assert service(['--url', self.orig_repo.path, '--revision=deb']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--revision=deb']), 0)
         self._check_files(['test-package_0.1.dsc', 'test-package_0.1.tar.gz'])
 
     def test_empty_export(self):
         """Test case where nothing is exported"""
-        assert service(['--url', self.orig_repo.path, '--revision=source']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--revision=source']), 0)
         self._check_files([])
-        assert service(['--url', self.orig_repo.path, '--rpm=no',
-                       '--deb=no']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--rpm=no', '--deb=no']), 0)
         self._check_files([])
 
     def test_basic_dual_export(self):
         """Test that simultaneous rpm and deb export works"""
-        assert service(['--url', self.orig_repo.path]) == 0
+        eq_(service(['--url', self.orig_repo.path]), 0)
         self._check_files(['test-package.spec', 'test-package_0.1.dsc',
                            'test-package_0.1.tar.gz'])
 
@@ -77,42 +76,42 @@ class TestService(UnitTestsBase):
         os.mkdir('foo')
         os.chmod('foo', 0)
         try:
-            assert service(['--url', self.orig_repo.path, '--outdir=foo']) == 1
+            eq_(service(['--url', self.orig_repo.path, '--outdir=foo']), 1)
         finally:
             os.chmod('foo', self.s_rwx)
-        assert service(['--url', self.orig_repo.path, '--rpm=yes',
-                        '--revision=source']) == 2
+        eq_(service(['--url', self.orig_repo.path, '--rpm=yes',
+                        '--revision=source']), 2)
 
     def test_gbp_deb_failure(self):
         """Test git-buildpackage (deb) failure"""
-        assert service(['--url', self.orig_repo.path, '--deb=yes',
-                        '--revision=source']) == 3
+        eq_(service(['--url', self.orig_repo.path, '--deb=yes',
+                        '--revision=source']), 3)
 
     def test_options_outdir(self):
         """Test the --outdir option"""
         outdir = os.path.join(self.tmpdir, 'outdir')
         args = ['--url', self.orig_repo.path, '--outdir=%s' % outdir]
-        assert service(args) == 0
+        eq_(service(args), 0)
         self._check_files(['test-package.spec', 'test-package_0.1.dsc',
                            'test-package_0.1.tar.gz'], outdir)
 
     def test_options_revision(self):
         """Test the --revision option"""
-        assert service(['--url', self.orig_repo.path, '--revision=master']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--revision=master']), 0)
         self._check_files(['test-package.spec', 'test-package_0.1.dsc',
                            'test-package_0.1.tar.gz'])
-        assert service(['--url', self.orig_repo.path, '--revision=foobar']) == 1
+        eq_(service(['--url', self.orig_repo.path, '--revision=foobar']), 1)
 
     def test_options_verbose(self):
         """Test the --verbose option"""
-        assert service(['--url', self.orig_repo.path, '--verbose=yes']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--verbose=yes']), 0)
         with assert_raises(SystemExit):
             service(['--url', self.orig_repo.path, '--verbose=foob'])
 
     def test_options_spec_vcs_tag(self):
         """Test the --spec-vcs-tag option"""
-        assert service(['--url', self.orig_repo.path,
-                        '--spec-vcs-tag=orig/%(tagname)s']) == 0
+        eq_(service(['--url', self.orig_repo.path,
+                        '--spec-vcs-tag=orig/%(tagname)s']), 0)
 
     def test_options_config(self):
         """Test the --config option"""
@@ -126,10 +125,10 @@ class TestService(UnitTestsBase):
         del os.environ['OBS_GIT_BUILDPACKAGE_REPO_CACHE_DIR']
 
         # Check that the repo cache we configured is actually used
-        assert (service(['--url', self.orig_repo.path, '--config', 'my.conf'])
+        ok_((service(['--url', self.orig_repo.path, '--config', 'my.conf']))
                 == 0)
-        assert not os.path.exists(default_cache), os.listdir('.')
-        assert os.path.exists('my-repo-cache'), os.listdir('.')
+        ok_(not os.path.exists(default_cache), os.listdir('.'))
+        ok_(os.path.exists('my-repo-cache'), os.listdir('.'))
 
     def test_user_group_config(self):
         """Test setting the user and group under which gbp is run"""
@@ -137,12 +136,12 @@ class TestService(UnitTestsBase):
         os.environ['OBS_GIT_BUILDPACKAGE_GBP_USER'] = str(os.getuid())
         os.environ['OBS_GIT_BUILDPACKAGE_GBP_GROUP'] = \
                 grp.getgrgid(os.getgid()).gr_name
-        assert service(['--url', self.orig_repo.path, '--revision=rpm']) == 0
+        eq_(service(['--url', self.orig_repo.path, '--revision=rpm']), 0)
 
         # Changing to non-existent user should fail
         os.environ['OBS_GIT_BUILDPACKAGE_GBP_USER'] = '_non_existent_user'
         del os.environ['OBS_GIT_BUILDPACKAGE_GBP_GROUP']
-        assert service(['--url', self.orig_repo.path, '--revision=rpm']) == 1
+        eq_(service(['--url', self.orig_repo.path, '--revision=rpm']), 1)
 
         # Return env
         del os.environ['OBS_GIT_BUILDPACKAGE_GBP_USER']