diff options
author | Jun Wang <junbill.wang@samsung.com> | 2016-03-18 21:49:38 +0800 |
---|---|---|
committer | Jun Wang <junbill.wang@samsung.com> | 2016-03-18 21:50:22 +0800 |
commit | 7c4962c9ce5cdab6d191f11297ea1b14dc464c14 (patch) | |
tree | 1fdc752991d068c9c72af4ab420f1280b5f7a1a2 | |
parent | 2f2269ffbf3c31f7df95ec2336d6c936c95a6e34 (diff) | |
download | git-buildpackage-7c4962c9ce5cdab6d191f11297ea1b14dc464c14.tar.gz git-buildpackage-7c4962c9ce5cdab6d191f11297ea1b14dc464c14.tar.bz2 git-buildpackage-7c4962c9ce5cdab6d191f11297ea1b14dc464c14.zip |
Modify unit test cases which called 'assert_raises' function
to fix pre-review test bugs on CentOS_6.
Change-Id: Ibb930eb107c18526876fc58428db359f9d31e716
-rw-r--r-- | tests/20_test_rpm.py | 56 | ||||
-rw-r--r-- | tests/component/rpm/test_buildpackage_rpm.py | 4 | ||||
-rw-r--r-- | tests/component/rpm/test_import_orig_rpm.py | 4 | ||||
-rw-r--r-- | tests/component/rpm/test_import_srpm.py | 4 | ||||
-rw-r--r-- | tests/component/rpm/test_pq_rpm.py | 4 | ||||
-rw-r--r-- | tests/component/rpm/test_rpm_ch.py | 4 | ||||
-rw-r--r-- | tests/test_rpm_changelog.py | 20 |
7 files changed, 96 insertions, 0 deletions
diff --git a/tests/20_test_rpm.py b/tests/20_test_rpm.py index 98ffbc9b..adf205f5 100644 --- a/tests/20_test_rpm.py +++ b/tests/20_test_rpm.py @@ -158,10 +158,15 @@ class TestSpecFile(RpmTestBase): def test_parse_raw(self): """Test parsing of a valid spec file""" + assert_raises(NoSpecError, SpecFile, None, None) + assert_raises(NoSpecError, SpecFile, 'filename', 'filedata') + + """ with assert_raises(NoSpecError): SpecFile(None, None) with assert_raises(NoSpecError): SpecFile('filename', 'filedata') + """ spec_filepath = os.path.join(SPEC_DIR, 'gbp-test.spec') with open(spec_filepath, 'r') as spec_fd: @@ -233,22 +238,36 @@ class TestSpecFile(RpmTestBase): eq_(spec.protected('_patches')(), {}) prev = spec.protected('_delete_tag')('invalidtag', None) + assert_raises(GbpError, spec.protected('_set_tag'), + 'Version', None, '', prev) + assert_raises(GbpError, spec.set_tag, + 'invalidtag', None, 'value') + + """ with assert_raises(GbpError): # Check that setting empty value fails spec.protected('_set_tag')('Version', None, '', prev) with assert_raises(GbpError): # Check that setting invalid tag with public method fails spec.set_tag('invalidtag', None, 'value') + """ # Mangle macros prev = spec.protected('_delete_special_macro')('patch', -1) spec.protected('_delete_special_macro')('patch', 123) spec.protected('_set_special_macro')('patch', 0, 'my new args', prev) + assert_raises(GbpError, spec.protected('_delete_special_macro'), + 'invalidmacro', 0) + assert_raises(GbpError, spec.protected('_set_special_macro'), + 'invalidmacro', 0, 'args', prev) + + """ with assert_raises(GbpError): spec.protected('_delete_special_macro')('invalidmacro', 0) with assert_raises(GbpError): spec.protected('_set_special_macro')('invalidmacro', 0, 'args', prev) + """ # Check resulting spec file spec.write_spec_file() @@ -260,12 +279,21 @@ class TestSpecFile(RpmTestBase): spec = SpecFileTester(spec_filepath) # Unknown/invalid section name + assert_raises(GbpError, spec.protected('_set_section'), + 'patch', 'new content\n') + """ with assert_raises(GbpError): spec.protected('_set_section')('patch', 'new content\n') + """ # Multiple sections with the same name + assert_raises(GbpError, spec.protected('_set_section'), + 'files', '%{_sysconfdir}/foo\n') + + """ with assert_raises(GbpError): spec.protected('_set_section')('files', '%{_sysconfdir}/foo\n') + """ def test_changelog(self): """Test changelog methods""" @@ -360,13 +388,27 @@ class TestUtilityFunctions(RpmTestBase): def test_guess_spec(self): """Test guess_spec() function""" # Spec not found + assert_raises(NoSpecError, guess_spec, + DATA_DIR, recursive=False) + + """ with assert_raises(NoSpecError): guess_spec(DATA_DIR, recursive=False) + """ + # Multiple spec files + assert_raises(NoSpecError, guess_spec, + DATA_DIR, recursive=True) + assert_raises(NoSpecError, guess_spec, + SPEC_DIR, recursive=False) + + """ with assert_raises(NoSpecError): guess_spec(DATA_DIR, recursive=True) with assert_raises(NoSpecError): guess_spec(SPEC_DIR, recursive=False) + """ + # Spec found spec = guess_spec(SPEC_DIR, recursive=False, preferred_name = 'gbp-test2.spec') @@ -388,10 +430,18 @@ class TestUtilityFunctions(RpmTestBase): repo.commit_all('Add spec file') # Spec not found + assert_raises(NoSpecError, guess_spec_repo, + repo, 'HEAD~1', recursive=True) + assert_raises(NoSpecError, guess_spec_repo, + repo, 'HEAD', recursive=False) + + """ with assert_raises(NoSpecError): guess_spec_repo(repo, 'HEAD~1', recursive=True) with assert_raises(NoSpecError): guess_spec_repo(repo, 'HEAD', recursive=False) + """ + # Spec found spec = guess_spec_repo(repo, 'HEAD', 'packaging', recursive=False) spec = guess_spec_repo(repo, 'HEAD', recursive=True) @@ -400,8 +450,14 @@ class TestUtilityFunctions(RpmTestBase): eq_(spec.specpath, 'packaging/gbp-test.spec') # Test spec_from_repo() + assert_raises(NoSpecError, spec_from_repo, + repo, 'HEAD~1', 'packaging/gbp-test.spec') + + """ with assert_raises(NoSpecError): spec_from_repo(repo, 'HEAD~1', 'packaging/gbp-test.spec') + """ + spec = spec_from_repo(repo, 'HEAD', 'packaging/gbp-test.spec') eq_(spec.specfile, 'gbp-test.spec') diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py index 88a66fc0..652b1528 100644 --- a/tests/component/rpm/test_buildpackage_rpm.py +++ b/tests/component/rpm/test_buildpackage_rpm.py @@ -101,8 +101,12 @@ class TestGbpRpm(RpmRepoTestBase): def test_invalid_args(self): """Check graceful exit when called with invalid args""" GitRepository.create('.') + assert_raises(SystemExit, mock_gbp, ['--git-invalid-arg']) + + """ with assert_raises(SystemExit): mock_gbp(['--git-invalid-arg']) + """ def test_outside_repo(self): """Run outside a git repository""" diff --git a/tests/component/rpm/test_import_orig_rpm.py b/tests/component/rpm/test_import_orig_rpm.py index a85366b1..ebf592a0 100644 --- a/tests/component/rpm/test_import_orig_rpm.py +++ b/tests/component/rpm/test_import_orig_rpm.py @@ -142,8 +142,12 @@ class TestImportOrig(ImportOrigTestBase): self._check_repo_state(repo, None, []) # Test invalid cmdline options + assert_raises(SystemExit, mock_import, ['--invalid-arg=123']) + + """ with assert_raises(SystemExit): mock_import(['--invalid-arg=123']) + """ def test_import_outside_repo(self): """Test importing when not in a git repository""" diff --git a/tests/component/rpm/test_import_srpm.py b/tests/component/rpm/test_import_srpm.py index 54898f7f..de28259a 100644 --- a/tests/component/rpm/test_import_srpm.py +++ b/tests/component/rpm/test_import_srpm.py @@ -45,8 +45,12 @@ class TestImportPacked(ComponentTestBase): def test_invalid_args(self): """See that import-srpm fails gracefully if called with invalid args""" eq_(mock_import([]), 1) + assert_raises(SystemExit, mock_import, ['--invalid-arg=123']) + + """ with assert_raises(SystemExit): mock_import(['--invalid-arg=123']) + """ def test_basic_import(self): """Test importing of non-native src.rpm""" diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py index 293244be..c14ea681 100644 --- a/tests/component/rpm/test_pq_rpm.py +++ b/tests/component/rpm/test_pq_rpm.py @@ -52,8 +52,12 @@ class TestPqRpm(RpmRepoTestBase): self._clear_log() # Test invalid cmdline options + assert_raises(SystemExit, mock_pq, ['--invalid-arg=123']) + + """ with assert_raises(SystemExit): mock_pq(['--invalid-arg=123']) + """ def test_import_outside_repo(self): """Run pq-rpm when not in a git repository""" diff --git a/tests/component/rpm/test_rpm_ch.py b/tests/component/rpm/test_rpm_ch.py index db03c845..4b3354b7 100644 --- a/tests/component/rpm/test_rpm_ch.py +++ b/tests/component/rpm/test_rpm_ch.py @@ -56,8 +56,12 @@ class TestRpmCh(RpmRepoTestBase): """See that git-rpm-ch fails gracefully when called with invalid args""" GitRepository.create('.') + assert_raises(SystemExit, mock_ch, ['--invalid-opt']) + + """ with assert_raises(SystemExit): mock_ch(['--invalid-opt']) + """ def test_import_outside_repo(self): """Run git-rpm-ch when not in a git repository""" diff --git a/tests/test_rpm_changelog.py b/tests/test_rpm_changelog.py index 29732936..22739f0e 100644 --- a/tests/test_rpm_changelog.py +++ b/tests/test_rpm_changelog.py @@ -40,8 +40,12 @@ class TestChangelogHeader(object): """Test missing properties""" time = datetime(2014, 01, 29, 12, 13, 14) header = _ChangelogHeader(RpmPkgPolicy, time, name="John", revision="1") + assert_raises(ChangelogError, str, header) + + """ with assert_raises(ChangelogError): str(header) + """ def test_container(self): """Test the container methods of the class""" @@ -190,6 +194,16 @@ class TestChangelogParser(object): def test_parse_section_fail(self): """Basic tests for failures of changelog section parsing""" + assert_raises(ChangelogError, self.parser.parse_section, + self.cl_broken_header_1) + assert_raises(ChangelogError, self.parser.parse_section, + self.cl_broken_header_2) + assert_raises(ChangelogError, self.parser.parse_section, + self.cl_broken_header_3) + assert_raises(ChangelogError, self.parser.parse_section, + self.cl_broken_header_4) + + """ with assert_raises(ChangelogError): self.parser.parse_section(self.cl_broken_header_1) @@ -201,11 +215,17 @@ class TestChangelogParser(object): with assert_raises(ChangelogError): self.parser.parse_section(self.cl_broken_header_4) + """ def test_parse_changelog_fail(self): """Basic tests for changelog parsing failures""" + assert_raises(ChangelogError, self.parser.raw_parse_string, + self.cl_broken_header_5) + + """ with assert_raises(ChangelogError): self.parser.raw_parse_string(self.cl_broken_header_5) + """ class TestChangelog(object): |