diff --git a/src/python/pants/util/objects.py b/src/python/pants/util/objects.py index 430a6fcef9a2..41c395b8e1bb 100644 --- a/src/python/pants/util/objects.py +++ b/src/python/pants/util/objects.py @@ -149,7 +149,7 @@ def __init__(self, type_name, msg, *args, **kwargs): full_msg, *args, **kwargs) -class TypedDatatypeInstanceConstructionError(Exception): +class TypedDatatypeInstanceConstructionError(TypeError): def __init__(self, type_name, msg, *args, **kwargs): full_msg = "error: in constructor of type {}: {}".format(type_name, msg) diff --git a/tests/python/pants_test/option/test_global_options.py b/tests/python/pants_test/option/test_global_options.py new file mode 100644 index 000000000000..9d6a622ffa5d --- /dev/null +++ b/tests/python/pants_test/option/test_global_options.py @@ -0,0 +1,21 @@ +# coding=utf-8 +# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +from __future__ import (absolute_import, division, generators, nested_scopes, print_function, + unicode_literals, with_statement) + +from pants.option.global_options import GlobMatchErrorBehavior +from pants_test.base_test import BaseTest + + +class GlobalOptionsTest(BaseTest): + + def test_exception_glob_match_constructor(self): + # NB: 'allow' is not a valid value for GlobMatchErrorBehavior. + with self.assertRaises(TypeError) as cm: + GlobMatchErrorBehavior(str('allow')) + expected_msg = ( + """error: in constructor of type GlobMatchErrorBehavior: type check error: +Value 'allow' for failure_behavior must be one of: [u'ignore', u'warn', u'error'].""") + self.assertEqual(str(cm.exception), expected_msg) diff --git a/tests/python/pants_test/util/test_objects.py b/tests/python/pants_test/util/test_objects.py index 951d566797b7..9992e228ad77 100644 --- a/tests/python/pants_test/util/test_objects.py +++ b/tests/python/pants_test/util/test_objects.py @@ -9,8 +9,7 @@ import pickle from abc import abstractmethod -from pants.util.objects import (Exactly, SubclassesOf, SuperclassesOf, TypeCheckError, - TypedDatatypeInstanceConstructionError, datatype) +from pants.util.objects import Exactly, SubclassesOf, SuperclassesOf, datatype from pants_test.base_test import BaseTest @@ -415,7 +414,7 @@ def test_instance_construction_errors(self): expected_msg = "__new__() takes exactly 2 arguments (3 given)" self.assertEqual(str(cm.exception), str(expected_msg)) - with self.assertRaises(TypedDatatypeInstanceConstructionError) as cm: + with self.assertRaises(TypeError) as cm: CamelCaseWrapper(nonneg_int=3) expected_msg = ( """error: in constructor of type CamelCaseWrapper: type check error: @@ -430,7 +429,7 @@ def test_instance_construction_errors(self): def test_type_check_errors(self): # single type checking failure - with self.assertRaises(TypeCheckError) as cm: + with self.assertRaises(TypeError) as cm: SomeTypedDatatype([]) expected_msg = ( """error: in constructor of type SomeTypedDatatype: type check error: @@ -438,7 +437,7 @@ def test_type_check_errors(self): self.assertEqual(str(cm.exception), str(expected_msg)) # type checking failure with multiple arguments (one is correct) - with self.assertRaises(TypeCheckError) as cm: + with self.assertRaises(TypeError) as cm: AnotherTypedDatatype(str('correct'), str('should be list')) expected_msg = ( """error: in constructor of type AnotherTypedDatatype: type check error: @@ -446,7 +445,7 @@ def test_type_check_errors(self): self.assertEqual(str(cm.exception), str(expected_msg)) # type checking failure on both arguments - with self.assertRaises(TypeCheckError) as cm: + with self.assertRaises(TypeError) as cm: AnotherTypedDatatype(3, str('should be list')) expected_msg = ( """error: in constructor of type AnotherTypedDatatype: type check error: @@ -454,14 +453,14 @@ def test_type_check_errors(self): field 'elements' was invalid: value 'should be list' (with type 'str') must satisfy this type constraint: Exactly(list).""") self.assertEqual(str(cm.exception), str(expected_msg)) - with self.assertRaises(TypeCheckError) as cm: + with self.assertRaises(TypeError) as cm: NonNegativeInt(str('asdf')) expected_msg = ( """error: in constructor of type NonNegativeInt: type check error: field 'an_int' was invalid: value 'asdf' (with type 'str') must satisfy this type constraint: Exactly(int).""") self.assertEqual(str(cm.exception), str(expected_msg)) - with self.assertRaises(TypeCheckError) as cm: + with self.assertRaises(TypeError) as cm: NonNegativeInt(-3) expected_msg = ( """error: in constructor of type NonNegativeInt: type check error: