def test_hanzi(self): m = Mock(return_value='foo.mp3') with patch('chinese.sound.download_sound', m): self.assertEqual( sound('图书馆', 'Baidu Translate'), '[sound:foo.mp3]' )
def test_bogus_source(self): with self.assertRaises(ValueError): sound('图书馆[foo bar baz]', 'foobar')
def test_ruby(self): sound('图书馆[foo bar baz]', 'baidu|zh') self.mock.assert_called_once_with('图书馆', 'baidu|zh')
def test_no_hanzi(self): with patch('chinese.sound.has_hanzi', Mock(return_value=False)): self.assertEqual(sound('foo', 'baidu|zh'), '')
def test_hanzi(self): with patch('chinese.sound.download', Mock(return_value='foo.mp3')): self.assertEqual(sound('图书馆', 'baidu|zh'), '[sound:foo.mp3]')
def test_not_implemented(self): with self.assertRaises(NotImplementedError): sound('图书馆[foo bar baz]', 'foo|bar')
def test_bogus_source(self): sound('图书馆[foo bar baz]', 'bogus') self.mock.assert_not_called()
def test_ruby(self): sound('图书馆[foo bar baz]', 'Baidu Translate') self.mock.assert_called_once_with('图书馆', ('baidu', 'zh'))
def test_disabled(self): with patch('chinese.sound.config', {'speech': None}): self.assertEqual(sound('图书馆'), '')
def test_hanzi(self): mock = Mock() mock.download = Mock(return_value='foo.mp3') self.mock.return_value = mock self.assertEqual(sound('图书馆', 'baidu|zh'), '[sound:foo.mp3]')