def test_merge_unicode_strings(self, open_mock): """ Bug 869538: Exception when merging unicode. """ mock_write = open_mock.return_value.__enter__.return_value.write msgs = [u"Désintéressé et fier de l'être"] _append_to_lang_file("dude.lang", msgs) mock_write.assert_called_once_with(u"\n\n;{msg}\n{msg}\n".format(msg=msgs[0]))
def test_merge_unicode_strings(self, open_mock): """ Bug 869538: Exception when merging unicode. """ mock_write = open_mock.return_value.__enter__.return_value.write msgs = [u"Désintéressé et fier de l'être"] _append_to_lang_file('dude.lang', msgs) mock_write.assert_called_once_with( u'\n\n;{msg}\n{msg}\n'.format(msg=msgs[0]))
def test_append_to_lang_file(self, codecs_mock): """Should attempt to write a correctly formatted langfile.""" _append_to_lang_file('dude.lang', self.good_messages) lang_vals = codecs_mock.open.return_value lang_vals = lang_vals.__enter__.return_value.write.call_args_list lang_vals = [call[0][0] for call in lang_vals] expected = [ u'\n\n# Said angrily, loudly, and repeatedly.\n' u';Is this your homework Larry?\nIs this your homework Larry?\n', u'\n\n;The Dude minds!\nThe Dude minds!\n', ] self.assertListEqual(lang_vals, expected)
def test_append_to_lang_file_dir_creation(self, codecs_mock, md_mock): """Should create dirs if required.""" path_exists = os.path.join(ROOT, 'locale', 'templates', 'firefox', 'fx.lang') path_dir_exists = os.path.join(ROOT, 'locale', 'templates', 'firefox', 'new.lang') path_new = os.path.join(ROOT, 'locale', 'de', 'does', 'not', 'exist.lang') with patch('os.path.dirname') as dn_mock: _append_to_lang_file(path_exists, {}) ok_(not dn_mock.called) dn_mock.reset_mock() dn_mock.return_value = os.path.join(ROOT, 'locale', 'templates', 'firefox') _append_to_lang_file(path_dir_exists, {}) ok_(dn_mock.called) md_mock.reset_mock() _append_to_lang_file(path_dir_exists, {}) ok_(not md_mock.called) md_mock.reset_mock() _append_to_lang_file(path_new, {}) ok_(md_mock.called)
def test_append_to_lang_file(self, open_mock): """ `_append_to_lang_file()` should append any new messages to a lang file. """ _append_to_lang_file("dude.lang", ["The Dude abides, man."]) mock_write = open_mock.return_value.__enter__.return_value.write mock_write.assert_called_once_with(u"\n\n;The Dude abides, man.\n" u"The Dude abides, man.\n") # make sure writing multiple strings works. mock_write.reset_mock() msgs = ["The Dude abides, man.", "Dammit Walter!"] _append_to_lang_file("dude.lang", msgs) expected = [((u"\n\n;{msg}\n{msg}\n".format(msg=msg),),) for msg in msgs] self.assertEqual(expected, mock_write.call_args_list)
def test_append_to_lang_file(self, open_mock): """ `_append_to_lang_file()` should append any new messages to a lang file. """ _append_to_lang_file('dude.lang', ['The Dude abides, man.']) mock_write = open_mock.return_value.__enter__.return_value.write mock_write.assert_called_once_with(u'\n\n;The Dude abides, man.\n' u'The Dude abides, man.\n') # make sure writing multiple strings works. mock_write.reset_mock() msgs = ['The Dude abides, man.', 'Dammit Walter!'] _append_to_lang_file('dude.lang', msgs) expected = [((u'\n\n;{msg}\n{msg}\n'.format(msg=msg),),) for msg in msgs] self.assertEqual(expected, mock_write.call_args_list)
def test_append_to_lang_file_dir_creation(self, codecs_mock, md_mock): """Should create dirs if required.""" path_exists = os.path.join(ROOT, "locale", "templates", "firefox", "fx.lang") path_dir_exists = os.path.join(ROOT, "locale", "templates", "firefox", "new.lang") path_new = os.path.join(ROOT, "locale", "de", "does", "not", "exist.lang") with patch("os.path.dirname") as dn_mock: _append_to_lang_file(path_exists, {}) ok_(not dn_mock.called) dn_mock.reset_mock() dn_mock.return_value = os.path.join(ROOT, "locale", "templates", "firefox") _append_to_lang_file(path_dir_exists, {}) ok_(dn_mock.called) md_mock.reset_mock() _append_to_lang_file(path_dir_exists, {}) ok_(not md_mock.called) md_mock.reset_mock() _append_to_lang_file(path_new, {}) ok_(md_mock.called)