def test_exits_if_command_line_arguments_cannot_be_parsed( self, create_config_instance_func, exit_func): conf = mock.Mock() conf.parse_command_line_options.return_value = False conf.num_remaining_platforms.return_value = 0 create_config_instance_func.return_value = conf captured_log = testfixtures.LogCapture() burton.run() captured_log.check((burton.logger_name, "ERROR", "Unable to parse command-line options")) captured_log.uninstall() exit_func.assert_called_with(1)
def test_run_fails_if_there_are_no_platforms_in_config_file( self, create_config_instance_func, exit_func): conf = mock.Mock() conf.num_remaining_platforms.return_value = 0 create_config_instance_func.return_value = conf captured_log = testfixtures.LogCapture() burton.run() captured_log.check( (burton.logger_name, "ERROR", "No platforms found in config file")) captured_log.uninstall() exit_func.assert_called_with(1)
def test_exits_if_cannot_read_platforms_from_config( self, create_config_instance_func, exit_func ): def _config_get(key): return { burton.Config.logging_level : "info", burton.Config.log_filename : "None", burton.Config.platform : None }[key] conf = mock.Mock() conf.get.side_effect = _config_get conf.parse_command_line_options.return_value = True conf._platform_queue = collections.deque(["foo"]) def _parse_next(): if len(conf._platform_queue) > 0: conf._platform_queue.popleft() return False conf.parse_config_file_for_next_platform.side_effect = _parse_next def _num_remaining_platforms(): return len(conf._platform_queue) conf.num_remaining_platforms.side_effect = _num_remaining_platforms create_config_instance_func.return_value = conf captured_log = testfixtures.LogCapture() burton.run() captured_log.check( ( burton.logger_name, "ERROR", "Unable to determine next platform in config file" ) ) captured_log.uninstall() exit_func.assert_called_with(1)
def test_exits_if_command_line_arguments_cannot_be_parsed( self, create_config_instance_func, exit_func ): conf = mock.Mock() conf.parse_command_line_options.return_value = False conf.num_remaining_platforms.return_value = 0 create_config_instance_func.return_value = conf captured_log = testfixtures.LogCapture() burton.run() captured_log.check( ( burton.logger_name, "ERROR", "Unable to parse command-line options" ) ) captured_log.uninstall() exit_func.assert_called_with(1)
def test_run_fails_if_there_are_no_platforms_in_config_file( self, create_config_instance_func, exit_func ): conf = mock.Mock() conf.num_remaining_platforms.return_value = 0 create_config_instance_func.return_value = conf captured_log = testfixtures.LogCapture() burton.run() captured_log.check( ( burton.logger_name, "ERROR", "No platforms found in config file" ) ) captured_log.uninstall() exit_func.assert_called_with(1)
def test_run(self, create_localized_resources_func, update_translation_file_func, create_db_instance_func, check_for_unmapped_strings_func, extract_mapping_func, extract_strings_func, update_base_localizations_func, create_vcs_class_func, config_logger_func, setup_default_logger_func, create_config_instance_func, isdir_func, chdir_func, exit_func): ran_all_tests = False test_db_name = "burton_test.sql" platform_string = "Test-platform" xlf_repo_path = "submodule" config_dict = { burton.Config.use_vcs: False, burton.Config.vcs_class: "burton.vcs.NoOp", burton.Config.commit_vcs: False, burton.Config.root_path: os.getcwd(), burton.Config.database_path: test_db_name, burton.Config.platform: platform_string, burton.Config.output_languages: ["French"], burton.Config.logging_level: "info", burton.Config.source_path: "foo", burton.Config.xlf_repo_path: xlf_repo_path } isdir_func.return_value = True def _config_get(key): return config_dict[key] conf = mock.Mock() conf._platform_queue = collections.deque([platform_string]) def _num_remaining_platforms(): return len(conf._platform_queue) def _parse_next(): return_value = conf._parse_config_file() if len(conf._platform_queue) > 0: conf._platform_queue.popleft() return return_value conf.num_remaining_platforms.side_effect = _num_remaining_platforms conf.parse_config_file_for_next_platform.side_effect = _parse_next conf.get.side_effect = _config_get conf.get_string_to_ignore.return_value = ["Ignore1", "Ignore2"] conf.parse_command_line_options.return_value = True conf._parse_config_file.return_value = False create_config_instance_func.return_value = conf chdir_directories = [] def _chdir(directory): chdir_directories.append(directory) chdir_func.side_effect = _chdir try: burton.run() conf._parse_config_file.return_value = True vcs_class = mock.Mock() create_vcs_class_func.return_value = vcs_class mapping = burton.StringMapping() mapping.add_mapping("String1", "Mapping1") extract_strings_func.return_value = ["String1"] extract_mapping_func.return_value = mapping mock_db = mock.Mock() mock_db.get_all_native_translations.return_value = ["Mapping1"] mock_db.get_native_translations_for_platform.return_value = [ "Mapping1" ] create_db_instance_func.return_value = mock_db conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(create_db_instance_func.called) self.assertTrue(mock_db.connect.called) self.assertFalse(mock_db.update_from_vcs.called) cwd = os.getcwd() self.assertEquals(chdir_directories, [cwd, cwd, cwd, "foo", cwd]) mock_db.write_string_mapping_for_platform.assert_called_with( platform_string, mapping.string_mapping_dict, ) update_translation_file_func.assert_called_with( conf, ["Mapping1"], ["Mapping1"], "French", vcs_class) create_localized_resources_func.assert_called_with( conf, ["Mapping1"], vcs_class) update_base_localizations_func.assert_called_with(conf, vcs_class) self.assertTrue(mock_db.disconnect.called) self.assertFalse(vcs_class.commit_changes.called) self.assertFalse(vcs_class.upload_changes.called) config_dict[burton.Config.use_vcs] = True conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(mock_db.update_from_vcs.called) config_dict[burton.Config.commit_vcs] = True conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(vcs_class.commit_changes.called) self.assertTrue(vcs_class.upload_changes.called) def _throw_exception(conf, native_translations, vcs_class): raise Exception("Sample Exception") create_localized_resources_func.side_effect = _throw_exception captured_log = testfixtures.LogCapture() burton.logging_handler.max_level = logging.ERROR conf._platform_queue = collections.deque([platform_string]) burton.run() captured_log.check( (burton.logger_name, "INFO", "Running for platform Test-platform"), (burton.logger_name, 'INFO', 'Writing string mapping to database'), (burton.logger_name, 'ERROR', 'Sample Exception'), (burton.logger_name, 'ERROR', 'Reverting checkout'), (burton.logger_name, "INFO", "Finished running for platform Test-platform")) captured_log.uninstall() exit_func.assert_called_with(1) ran_all_tests = True except Exception as e: print e self.assertFalse(True) finally: if os.path.exists(test_db_name): os.remove(test_db_name) self.assertTrue(ran_all_tests)
logger.error("Installing missing dependencies") current_dir = os.getcwd() os.chdir(root_path) return_code = subprocess.call([ sys.executable, "setup.py", "install" ]) os.chdir(current_dir) if return_code == 0: logger.error("Finished installing dependencies") logger.error("Run this script again to run localization") else: logger.error("Unable to install dependencies") logger.error("This is most likely a permissions problem") logger.error("Please try running again with administrator privileges") logger.error("The exact error(s) are detailed in the output above") exit(1) import burton burton.run()
def test_run( self, create_localized_resources_func, update_translation_file_func, create_db_instance_func, check_for_unmapped_strings_func, extract_mapping_func, extract_strings_func, update_base_localizations_func, create_vcs_class_func, config_logger_func, setup_default_logger_func, create_config_instance_func, isdir_func, chdir_func, exit_func ): ran_all_tests = False test_db_name = "burton_test.sql" platform_string = "Test-platform" xlf_repo_path = "submodule" config_dict = { burton.Config.use_vcs : False, burton.Config.vcs_class : "burton.vcs.NoOp", burton.Config.commit_vcs : False, burton.Config.root_path : os.getcwd(), burton.Config.database_path : test_db_name, burton.Config.platform : platform_string, burton.Config.output_languages : [ "French" ], burton.Config.logging_level : "info", burton.Config.source_path : "foo", burton.Config.xlf_repo_path : xlf_repo_path } isdir_func.return_value = True def _config_get(key): return config_dict[key] conf = mock.Mock() conf._platform_queue = collections.deque([platform_string]) def _num_remaining_platforms(): return len(conf._platform_queue) def _parse_next(): return_value = conf._parse_config_file() if len(conf._platform_queue) > 0: conf._platform_queue.popleft() return return_value conf.num_remaining_platforms.side_effect = _num_remaining_platforms conf.parse_config_file_for_next_platform.side_effect = _parse_next conf.get.side_effect = _config_get conf.get_string_to_ignore.return_value = [ "Ignore1", "Ignore2" ] conf.parse_command_line_options.return_value = True conf._parse_config_file.return_value = False create_config_instance_func.return_value = conf chdir_directories = [] def _chdir(directory): chdir_directories.append(directory) chdir_func.side_effect = _chdir try: burton.run() conf._parse_config_file.return_value = True vcs_class = mock.Mock() create_vcs_class_func.return_value = vcs_class mapping = burton.StringMapping() mapping.add_mapping("String1", "Mapping1") extract_strings_func.return_value = [ "String1" ] extract_mapping_func.return_value = mapping mock_db = mock.Mock() mock_db.get_all_native_translations.return_value = [ "Mapping1" ] mock_db.get_native_translations_for_platform.return_value = [ "Mapping1" ] create_db_instance_func.return_value = mock_db conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(create_db_instance_func.called) self.assertTrue(mock_db.connect.called) self.assertFalse(mock_db.update_from_vcs.called) cwd = os.getcwd() self.assertEquals( chdir_directories, [ cwd, cwd, cwd, "foo", cwd ] ) mock_db.write_string_mapping_for_platform.assert_called_with( platform_string, mapping.string_mapping_dict, ) update_translation_file_func.assert_called_with( conf, [ "Mapping1" ], [ "Mapping1" ], "French", vcs_class ) create_localized_resources_func.assert_called_with( conf, [ "Mapping1" ], vcs_class ) update_base_localizations_func.assert_called_with(conf, vcs_class) self.assertTrue(mock_db.disconnect.called) self.assertFalse(vcs_class.commit_changes.called) self.assertFalse(vcs_class.upload_changes.called) config_dict[burton.Config.use_vcs] = True conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(mock_db.update_from_vcs.called) config_dict[burton.Config.commit_vcs] = True conf._platform_queue = collections.deque([platform_string]) burton.run() self.assertTrue(vcs_class.commit_changes.called) self.assertTrue(vcs_class.upload_changes.called) def _throw_exception(conf, native_translations, vcs_class): raise Exception("Sample Exception") create_localized_resources_func.side_effect = _throw_exception captured_log = testfixtures.LogCapture() burton.logging_handler.max_level = logging.ERROR conf._platform_queue = collections.deque([platform_string]) burton.run() captured_log.check( ( burton.logger_name, "INFO", "Running for platform Test-platform" ), ( burton.logger_name, 'INFO', 'Writing string mapping to database' ), (burton.logger_name, 'ERROR', 'Sample Exception'), (burton.logger_name, 'ERROR', 'Reverting checkout'), ( burton.logger_name, "INFO", "Finished running for platform Test-platform" ) ) captured_log.uninstall() exit_func.assert_called_with(1) ran_all_tests = True except Exception as e: print e self.assertFalse(True) finally: if os.path.exists(test_db_name): os.remove(test_db_name) self.assertTrue(ran_all_tests)
__import__(requirement) except ImportError: import subprocess import time logger.error("Installing missing dependencies") current_dir = os.getcwd() os.chdir(root_path) return_code = subprocess.call([sys.executable, "setup.py", "install"]) os.chdir(current_dir) if return_code == 0: logger.error("Finished installing dependencies") logger.error("Run this script again to run localization") else: logger.error("Unable to install dependencies") logger.error("This is most likely a permissions problem") logger.error("Please try running again with administrator privileges") logger.error("The exact error(s) are detailed in the output above") exit(1) import burton burton.run()