Skip to content

Commit

Permalink
add the raises exception and use self.assertRaises to test for the ex…
Browse files Browse the repository at this point in the history
…ception raised.
  • Loading branch information
chinyeungli committed Mar 4, 2014
1 parent 6132cfd commit 110713d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion about_code_tool/genabout.py
Expand Up @@ -204,7 +204,7 @@ def verify_license_files(self, input_list, project_dir):
except Exception as e:
print(repr(e))
print("The input does not have the 'license_text_file' key which is required.")
sys.exit(errno.EINVAL)
raise Exception(repr(e))
return license_files_list

def request_license_data(self, url, username, api_key, license_key):
Expand Down Expand Up @@ -595,6 +595,8 @@ def main(parser, options, args):
copy_license_path += '/'
project_parent_dir = dirname(copy_license_path)
license_list = gen.verify_license_files(input_list, project_parent_dir)
if not license_list:
print("None of the 'license_text_file' is found. '--copy_license' is ignored.")
gen.copy_license_files(output_path, license_list, project_parent_dir)

if extract_license:
Expand Down
15 changes: 11 additions & 4 deletions about_code_tool/tests/test_genabout.py
Expand Up @@ -14,13 +14,13 @@
# limitations under the License.
# =============================================================================

from __future__ import print_function
from __future__ import with_statement
from __future__ import print_function, with_statement

import os
import unittest
import tempfile
import shutil
import tempfile
import unittest

from os.path import abspath, dirname, join

from about_code_tool import genabout
Expand Down Expand Up @@ -255,6 +255,13 @@ def test_verify_license_files_not_exist(self):
self.assertTrue(len(gen.warnings) == 1, "Should return 1 warning.")
self.assertFalse(gen.errors, "No errors should be returned.")

def test_verify_license_files_no_key(self):
gen = genabout.GenAbout()
input_list = [{'version': '0.8.1', 'about_file': 'about.py.ABOUT',
'name': 'ABOUT tool', 'about_resource': '.'}]
path = '.'
self.assertRaises(Exception, gen.verify_license_files, input_list, path)

def test_gen_license_list_license_text_file_no_value(self):
gen = genabout.GenAbout()
input_list = {'about_file': '/tmp/3pp/opensans/', 'name': 'OpenSans Fonts',
Expand Down

0 comments on commit 110713d

Please sign in to comment.