22
33import os
44import sys
5- from unittest import TestCase , mock
5+ from unittest import mock
66
7- from pytest import main
7+ from pytest import main , raises
88
99from g2p import make_g2p
1010from g2p .exceptions import MalformedMapping , NeuralDependencyError
1616# mypy: disable-error-code="attr-defined"
1717
1818
19- class TransducerTest ( TestCase ) :
19+ class TestTransducer :
2020 """Basic Transducer Test"""
2121
2222 @classmethod
23- def setUpClass (cls ):
23+ def setup_class (cls ):
2424 cls .test_mapping_moh = Mapping .find_mapping (
2525 in_lang = "moh-equiv" , out_lang = "moh-ipa"
2626 )
@@ -93,9 +93,9 @@ def setUpClass(cls):
9393 def test_no_neural_dependencies (self ):
9494 """This tests what happens if a user tries to create a neural g2p without installing the dependencies. Other neural tests (for when deps are installed are in test_neural.py module.)"""
9595 with mock .patch ("g2p.mappings.utils.has_neural_support" , return_value = False ):
96- with self . assertRaises (NeuralDependencyError ):
96+ with raises (NeuralDependencyError ):
9797 make_g2p ("foo" , "bar" , neural = True )
98- with self . assertRaises (NeuralDependencyError ):
98+ with raises (NeuralDependencyError ):
9999 make_g2p ("str" , "str-ipa" , neural = True )
100100
101101 def test_properties (self ):
@@ -131,11 +131,11 @@ def test_graph_properties(self):
131131 tg .debugger = [["spam" , "spam" , "spam" , "spam" ]]
132132 assert 1 == len (tg .debugger )
133133 assert 4 == len (tg .debugger [0 ])
134- with self . assertRaises (ValueError ):
134+ with raises (ValueError ):
135135 tg .input_nodes = ("foo" , "bar" , "baz" )
136- with self . assertRaises (ValueError ):
136+ with raises (ValueError ):
137137 tg .output_nodes = ("foo" , "bar" , "baz" )
138- with self . assertRaises (ValueError ):
138+ with raises (ValueError ):
139139 tg .tiers = ["spam" , "spam" , "eggs" , "spam" ]
140140 tg = self .test_trans ("abab" )
141141 tg += tg
@@ -160,15 +160,15 @@ def test_composite_graph_properties(self):
160160 assert [(0 == "b" ), (1 , "b" ), (2 , "b" ), (3 , "b" )], ctg .input_nodes
161161 ctg .output_string = "baba"
162162 assert [(0 == "b" ), (1 , "a" ), (2 , "b" ), (3 , "a" )], ctg .output_nodes
163- with self . assertRaises (ValueError ):
163+ with raises (ValueError ):
164164 ctg .debugger = [["spam" , "spam" , "spam" , "spam" ]]
165- with self . assertRaises (ValueError ):
165+ with raises (ValueError ):
166166 ctg .edges = [(0 , 1 ), (1 , 0 ), (2 , 3 ), (3 , 2 )]
167- with self . assertRaises (ValueError ):
167+ with raises (ValueError ):
168168 ctg .input_nodes = ("foo" , "bar" , "baz" )
169- with self . assertRaises (ValueError ):
169+ with raises (ValueError ):
170170 ctg .output_nodes = ("foo" , "bar" , "baz" )
171- with self . assertRaises (ValueError ):
171+ with raises (ValueError ):
172172 ctg .tiers = ["spam" , "spam" , "eggs" , "spam" ]
173173 ctg = self .test_trans_composite ("aba" )
174174 ctg += ctg
@@ -244,7 +244,7 @@ def test_case_preservation(self):
244244 # I guess it's arguable what should happen here, but I'll just change case if any of the characters are differently cased
245245 assert transducer ("Tlaba" ).output_string == "\u2144 aba"
246246 # case equivalencies that are not the same length cause indexing errors in the current implementation
247- with self . assertRaises (MalformedMapping ):
247+ with raises (MalformedMapping ):
248248 Mapping (
249249 rules = [
250250 {"in" : "'a" , "out" : "b" },
@@ -257,7 +257,7 @@ def test_case_preservation(self):
257257 case_equivalencies = {"λ" : "\u2144 \u2144 \u2144 " },
258258 )
259259
260- with self . assertRaises (MalformedMapping ):
260+ with raises (MalformedMapping ):
261261 _ = Mapping (
262262 rules = [{"in" : "a" , "out" : "b" }],
263263 case_sensitive = True ,
0 commit comments