def setUp(self): super(TestGenerate, self).setUp() self.configuration = config.Configuration() # Subtract 1 second to help comparisons with file-modify time succeed, # since os.path.getmtime() is not millisecond-accurate self.start_time = datetime.now(UTC) - timedelta(seconds=1)
def setUpClass(cls): cfg = os.path.join('conf', 'locale', 'config.yaml') config.CONFIGURATION = config.Configuration(cfg) sys.stderr.write( "\nExtracting i18n strings and generating dummy translations; " "this may take a few minutes\n") sys.stderr.flush() extract.main(verbosity=0, config=cfg) dummy.main(verbosity=0, config=cfg)
def test_merge(self): """ Tests merge script on English source files. """ test_configuration = config.Configuration(root_dir=MOCK_DJANGO_APP_DIR) filename = Path.joinpath(test_configuration.source_messages_dir, random_name()) generate.merge(test_configuration, test_configuration.source_locale, target=filename) self.assertTrue(Path.exists(filename)) Path.remove(filename)
def _setup_i18n_test_config(self, root_dir=MOCK_APPLICATION_DIR, preserve_locale_paths=None, clean_paths=None): self.configuration = config.Configuration(root_dir=root_dir) self.preserve_locale_paths = preserve_locale_paths if preserve_locale_paths is not None else [] self.clean_paths = clean_paths if clean_paths is not None else [] # Copy off current state of original locale dirs for locale_path in self.preserve_locale_paths: tmp = self._get_tmp_locale_path(locale_path) path.rmtree_p(path(tmp)) path.copytree(path(locale_path), path(tmp))
def test_configuration_overrides(self): # Test overriding the default configuration, and that overrides # values are recognized config_filename = os.path.normpath(os.path.join('tests', 'data', 'config.yaml')) config.CONFIGURATION = config.Configuration(config_filename) locales = config.CONFIGURATION.locales self.assertIn('ar', locales) self.assertEqual('eo', config.CONFIGURATION.dummy_locales[0]) self.assertEqual('en', config.CONFIGURATION.source_locale) self.assertEqual( 'https://www.transifex.com/open-edx-releases/cypress-release/', config.CONFIGURATION.TRANSIFEX_URL )
def test_default_configuration(self, root_dir): """ Make sure we have a valid defaults in the configuration file: that it contains an 'en' locale, has values for dummy_locale, source_locale, and others. """ test_configuration = config.Configuration(root_dir=root_dir) self.assertIsNotNone(test_configuration) # these will just be defaults locales = test_configuration.locales self.assertIsNotNone(locales) self.assertIsInstance(locales, list) self.assertEqual('https://www.transifex.com/open-edx/edx-platform/', test_configuration.TRANSIFEX_URL)
def test_merge_with_missing_sources_strict(self): """ Tests merge script when some source files are missing. In strict mode, an exception should be raised. """ test_configuration = config.Configuration(root_dir=MOCK_DJANGO_APP_DIR) filename = Path.joinpath(test_configuration.source_messages_dir, random_name()) with self.assertRaises(ValueError): generate.merge( test_configuration, test_configuration.source_locale, sources=("django-partial.po", "nonexistingfile.po"), target=filename, fail_if_missing=True, ) self.assertFalse(Path.exists(filename))
def test_merge_with_missing_sources(self): """ Tests merge script when some source files are missing. The existing files should be merged anyway. """ test_configuration = config.Configuration(root_dir=MOCK_DJANGO_APP_DIR) filename = Path.joinpath(test_configuration.source_messages_dir, random_name()) generate.merge( test_configuration, test_configuration.source_locale, sources=("django-partial.po", "nonexistingfile.po"), target=filename, fail_if_missing=False, ) self.assertTrue(Path.exists(filename)) Path.remove(filename)
def test_valid_configuration(self): """ Make sure we have a valid configuration file, and that it contains an 'en' locale. Also check values of dummy_locale and source_locale. """ self.assertIsNotNone(config.CONFIGURATION) # these will just be defaults locales = config.CONFIGURATION.locales self.assertIsNotNone(locales) self.assertIsInstance(locales, list) config_filename = os.path.normpath(os.path.join('tests', 'data', 'config.yaml')) config.CONFIGURATION = config.Configuration(config_filename) self.assertIn('en', locales) self.assertEqual('eo', config.CONFIGURATION.dummy_locales[0]) self.assertEqual('en', config.CONFIGURATION.source_locale)
def setUp(self): global SETUP_HAS_RUN super(TestExtract, self).setUp() # Subtract 1 second to help comparisons with file-modify time succeed, # since os.path.getmtime() is not millisecond-accurate self.start_time = datetime.now() - timedelta(seconds=1) self.mock_path = Path.joinpath(MOCK_DJANGO_APP_DIR, "locale", "mock") self.mock_mapped_path = Path.joinpath(MOCK_DJANGO_APP_DIR, "locale", "mock_mapped") self._setup_i18n_test_config(root_dir=MOCK_DJANGO_APP_DIR, preserve_locale_paths=(self.mock_path, ), clean_paths=(self.mock_mapped_path, )) self.configuration = config.Configuration(root_dir=MOCK_DJANGO_APP_DIR) if not SETUP_HAS_RUN: # Run extraction script. Warning, this takes 1 minute or more extract.main(verbosity=0, config=self.configuration._filename, root_dir=MOCK_DJANGO_APP_DIR) SETUP_HAS_RUN = True
def test_no_config(self): config_filename = os.path.normpath(os.path.join(config.LOCALE_DIR, 'no_such_file')) with self.assertRaises(Exception): config.Configuration(config_filename)
def test_config(self): config_filename = os.path.normpath(os.path.join('tests', 'data', 'config.yaml')) cfg = config.Configuration(config_filename) self.assertEqual(cfg.source_locale, 'en')