@@ -1641,7 +1641,7 @@ def int_to_string(x):
16411641 error_regex = "Type-hint for argument: 'x' violated. Expected an instance "
16421642 "of {}, instead found some_string, an instance of {}." .format (int , str )
16431643
1644- with self .assertRaisesRegex (Exception , error_regex ) as e :
1644+ with self .assertRaisesRegex (Exception , error_regex ):
16451645 self .p .run ()
16461646
16471647 def test_run_time_type_checking_enabled_types_satisfied (self ):
@@ -1688,9 +1688,9 @@ def is_even_as_key(a):
16881688 # Although all the types appear to be correct when checked at pipeline
16891689 # construction. Runtime type-checking should detect the 'is_even_as_key' is
16901690 # returning Tuple[int, int], instead of Tuple[bool, int].
1691- error_regex = r".* Runtime type violation detected"
1691+ error_regex = " Runtime type violation detected"
16921692
1693- with self .assertRaisesRegex (Exception , error_regex ) as e :
1693+ with self .assertRaisesRegex (Exception , error_regex ):
16941694 self .p .run ()
16951695
16961696 def test_pipeline_checking_satisfied_run_time_checking_satisfied (self ):
@@ -1720,9 +1720,9 @@ def test_pipeline_runtime_checking_violation_simple_type_input(self):
17201720 # The type-hinted applied via the 'with_input_types()' method indicates the
17211721 # ParDo should receive an instance of type 'str', however an 'int' will be
17221722 # passed instead.
1723- error_regex = r".* Runtime type violation detected"
1723+ error_regex = " Runtime type violation detected"
17241724
1725- with self .assertRaisesRegex (Exception , error_regex ) as e :
1725+ with self .assertRaisesRegex (Exception , error_regex ):
17261726 (
17271727 self .p
17281728 | beam .Create ([1 , 1 , 1 ])
@@ -1735,9 +1735,9 @@ def test_pipeline_runtime_checking_violation_composite_type_input(self):
17351735 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
17361736 self .p ._options .view_as (TypeOptions ).pipeline_type_check = False
17371737
1738- error_regex = r".* Runtime type violation detected"
1738+ error_regex = " Runtime type violation detected"
17391739
1740- with self .assertRaisesRegex (Exception , error_regex ) as e :
1740+ with self .assertRaisesRegex (Exception , error_regex ):
17411741 (
17421742 self .p
17431743 | beam .Create ([(1 , 3.0 ), (2 , 4.9 ), (3 , 9.5 )])
@@ -1759,26 +1759,29 @@ def test_pipeline_runtime_checking_violation_simple_type_output(self):
17591759 (
17601760 'ToInt' >> beam .FlatMap (lambda x : [float (x )]).with_input_types (
17611761 int ).with_output_types (int )).get_type_hints ())
1762- error_regex = r".* "
1762+ error_regex = " "
17631763
17641764 if self .p ._options .view_as (TypeOptions ).runtime_type_check :
1765- error_regex += "Runtime type violation detected within "
1766- "ParDo(ToInt): According to type-hint expected output should be of type "
1767- "{}. Instead, received '1.0', an instance of type {}." .format (int , float )
1765+ error_regex = (
1766+ "Runtime type violation detected within ParDo\\ (ToInt\\ ):" +
1767+ " According to type-hint expected output should be of type <class " +
1768+ "'int'>. Instead, received '1.0', an instance of type <class 'float'>"
1769+ )
17681770
17691771 if self .p ._options .view_as (TypeOptions ).performance_runtime_type_check :
1770- error_regex += "Runtime type violation detected within ToInt: "
1771- "Type-hint for argument: 'x' violated. Expected an instance of "
1772- "{}, instead found 1.0, an instance of {}" .format (int , float )
1772+ error_regex = (
1773+ "Runtime type violation detected within ToInt: Type-hint " +
1774+ "for argument: 'x' violated. Expected an instance of <class 'int'>, "
1775+ + "instead found 1.0, an instance of <class 'float'>" )
17731776
1774- with self .assertRaisesRegex (Exception , error_regex ) as e :
1777+ with self .assertRaisesRegex (Exception , error_regex ):
17751778 (
17761779 self .p
17771780 | beam .Create ([1 , 1 , 1 ])
17781781 | (
17791782 'ToInt' >> beam .FlatMap (lambda x : [float (x )]).with_input_types (
17801783 int ).with_output_types (int )))
1781- self .p .run ()
1784+ self .p .run (). wait_until_finish ()
17821785
17831786 def test_pipeline_runtime_checking_violation_composite_type_output (self ):
17841787 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
@@ -1787,12 +1790,13 @@ def test_pipeline_runtime_checking_violation_composite_type_output(self):
17871790 # The type-hinted applied via the 'returns()' method indicates the ParDo
17881791 # should return an instance of type: Tuple[float, int]. However, an instance
17891792 # of 'int' will be generated instead.
1790- error_regex = "Runtime type violation detected within "
1791- "ParDo(Swap): Tuple type constraint violated. "
1792- "Valid object instance must be of type 'tuple'. Instead, "
1793- "an instance of 'float' was received."
1793+ error_regex = (
1794+ "Runtime type violation detected within " +
1795+ "ParDo\\ (Swap\\ ): Tuple type constraint violated. " +
1796+ "Valid object instance must be of type 'tuple'. Instead, " +
1797+ "an instance of 'float' was received." )
17941798
1795- with self .assertRaisesRegex (Exception , error_regex ) as e :
1799+ with self .assertRaisesRegex (Exception , error_regex ):
17961800 (
17971801 self .p
17981802 | beam .Create ([(1 , 3.0 ), (2 , 4.9 ), (3 , 9.5 )])
@@ -1812,18 +1816,18 @@ def test_pipeline_runtime_checking_violation_with_side_inputs_decorator(self):
18121816 def add (a , b ):
18131817 return a + b
18141818
1815- error_regex = r".* Runtime type violation detected"
1819+ error_regex = " Runtime type violation detected"
18161820
1817- with self .assertRaisesRegex (Exception , error_regex ) as e :
1821+ with self .assertRaisesRegex (Exception , error_regex ):
18181822 (self .p | beam .Create ([1 , 2 , 3 , 4 ]) | 'Add 1' >> beam .Map (add , 1.0 ))
18191823 self .p .run ()
18201824
18211825 def test_pipeline_runtime_checking_violation_with_side_inputs_via_method (self ): # pylint: disable=line-too-long
18221826 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
18231827 self .p ._options .view_as (TypeOptions ).pipeline_type_check = False
18241828
1825- error_regex = r".* Runtime type violation detected"
1826- with self .assertRaisesRegex (Exception , error_regex ) as e :
1829+ error_regex = " Runtime type violation detected"
1830+ with self .assertRaisesRegex (Exception , error_regex ):
18271831 (
18281832 self .p
18291833 | beam .Create ([1 , 2 , 3 , 4 ])
@@ -1925,12 +1929,12 @@ def test_combine_runtime_type_check_violation_using_decorators(self):
19251929 def iter_mul (ints ):
19261930 return str (reduce (operator .mul , ints , 1 ))
19271931
1928- error_regex = r".*Runtime type violation detected within "
1929- "Mul/CombinePerKey: "
1930- " Type-hint for return type violated. "
1931- "Expected an instance of {}, instead found" .format (int )
1932+ error_regex = (
1933+ "Runtime type violation detected within " +
1934+ "Mul/CombinePerKey: Type-hint for return type violated. " +
1935+ "Expected an instance of {}, instead found" .format (int ) )
19321936
1933- with self .assertRaisesRegex (Exception , error_regex ) as e :
1937+ with self .assertRaisesRegex (Exception , error_regex ):
19341938 (
19351939 self .p
19361940 | 'K' >> beam .Create ([5 , 5 , 5 , 5 ]).with_output_types (int )
@@ -1986,12 +1990,13 @@ def test_combine_runtime_type_check_violation_using_methods(self):
19861990 self .p ._options .view_as (TypeOptions ).pipeline_type_check = False
19871991 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
19881992
1989- error_regex = r".*Runtime type violation detected within "
1990- "ParDo(SortJoin/KeyWithVoid): "
1991- "Type-hint for argument: 'v' violated. Expected an instance of "
1992- "{}, instead found 0, an instance of {}." .format (str , int )
1993+ error_regex = (
1994+ "Runtime type violation detected within " +
1995+ "ParDo\\ (SortJoin/KeyWithVoid\\ ): " +
1996+ "Type-hint for argument: 'v' violated. Expected an instance of " +
1997+ "<class 'str'>, instead found 0, an instance of <class 'int'>." )
19931998
1994- with self .assertRaisesRegex (Exception , error_regex ) as e :
1999+ with self .assertRaisesRegex (Exception , error_regex ):
19952000 (
19962001 self .p
19972002 | beam .Create ([0 ]).with_output_types (int )
@@ -2054,9 +2059,9 @@ def test_mean_globally_runtime_checking_violated(self):
20542059 self .p ._options .view_as (TypeOptions ).pipeline_type_check = False
20552060 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
20562061
2057- error_regex = r".* Runtime type violation detected"
2062+ error_regex = " Runtime type violation detected"
20582063
2059- with self .assertRaisesRegex (Exception , error_regex ) as e :
2064+ with self .assertRaisesRegex (Exception , error_regex ):
20602065 (
20612066 self .p
20622067 | 'C' >> beam .Create (['t' , 'e' , 's' , 't' ]).with_output_types (str )
@@ -2114,9 +2119,9 @@ def test_mean_per_key_runtime_checking_violated(self):
21142119 self .p ._options .view_as (TypeOptions ).pipeline_type_check = False
21152120 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
21162121
2117- error_regex = r".* Runtime type violation detected"
2122+ error_regex = " Runtime type violation detected"
21182123
2119- with self .assertRaisesRegex (Exception , error_regex ) as e :
2124+ with self .assertRaisesRegex (Exception , error_regex ):
21202125 (
21212126 self .p
21222127 | beam .Create (range (5 )).with_output_types (int )
@@ -2443,9 +2448,9 @@ def test_to_dict_runtime_check_satisfied(self):
24432448 def test_runtime_type_check_python_type_error (self ):
24442449 self .p ._options .view_as (TypeOptions ).runtime_type_check = True
24452450
2446- error_regex = r".* object of type 'int' has no len()"
2451+ error_regex = " object of type 'int' has no len()"
24472452
2448- with self .assertRaisesRegex (Exception , error_regex ) as e :
2453+ with self .assertRaisesRegex (Exception , error_regex ):
24492454 (
24502455 self .p
24512456 | beam .Create ([1 , 2 , 3 ]).with_output_types (int )
0 commit comments