|
16 | 16 | from django.core.management.utils import find_command
|
17 | 17 | from django.test import SimpleTestCase, override_settings
|
18 | 18 | from django.test.utils import captured_stderr, captured_stdout
|
| 19 | +from django.utils._os import symlinks_supported |
19 | 20 | from django.utils.translation import TranslatorCommentWarning
|
20 | 21 |
|
21 | 22 | from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree
|
@@ -382,7 +383,10 @@ def test_makemessages_gettext_version(self, mocked_popen_wrapper):
|
382 | 383 | cmd.gettext_version
|
383 | 384 |
|
384 | 385 | def test_po_file_encoding_when_updating(self):
|
385 |
| - """Update of PO file doesn't corrupt it with non-UTF-8 encoding on Python3+Windows (#23271)""" |
| 386 | + """ |
| 387 | + Update of PO file doesn't corrupt it with non-UTF-8 encoding on Windows |
| 388 | + (#23271). |
| 389 | + """ |
386 | 390 | BR_PO_BASE = 'locale/pt_BR/LC_MESSAGES/django'
|
387 | 391 | shutil.copyfile(BR_PO_BASE + '.pristine', BR_PO_BASE + '.po')
|
388 | 392 | management.call_command('makemessages', locale=['pt_BR'], verbosity=0)
|
@@ -472,29 +476,20 @@ def setUp(self):
|
472 | 476 | self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
|
473 | 477 |
|
474 | 478 | def test_symlink(self):
|
475 |
| - # On Python < 3.2 os.symlink() exists only on Unix |
476 |
| - if hasattr(os, 'symlink'): |
477 |
| - if os.path.exists(self.symlinked_dir): |
478 |
| - self.assertTrue(os.path.islink(self.symlinked_dir)) |
479 |
| - else: |
480 |
| - # On Python >= 3.2) os.symlink() exists always but then can |
481 |
| - # fail at runtime when user hasn't the needed permissions on |
482 |
| - # Windows versions that support symbolink links (>= 6/Vista). |
483 |
| - # See Python issue 9333 (http://bugs.python.org/issue9333). |
484 |
| - # Skip the test in that case |
485 |
| - try: |
486 |
| - os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir) |
487 |
| - except (OSError, NotImplementedError): |
488 |
| - self.skipTest("os.symlink() is available on this OS but can't be used by this user.") |
489 |
| - os.chdir(self.test_dir) |
490 |
| - management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True) |
491 |
| - self.assertTrue(os.path.exists(self.PO_FILE)) |
492 |
| - with open(self.PO_FILE, 'r') as fp: |
493 |
| - po_contents = fp.read() |
494 |
| - self.assertMsgId('This literal should be included.', po_contents) |
495 |
| - self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html') |
| 479 | + if os.path.exists(self.symlinked_dir): |
| 480 | + self.assertTrue(os.path.islink(self.symlinked_dir)) |
496 | 481 | else:
|
497 |
| - self.skipTest("os.symlink() not available on this OS + Python version combination.") |
| 482 | + if symlinks_supported(): |
| 483 | + os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir) |
| 484 | + else: |
| 485 | + self.skipTest("os.symlink() not available on this OS + Python version combination.") |
| 486 | + os.chdir(self.test_dir) |
| 487 | + management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True) |
| 488 | + self.assertTrue(os.path.exists(self.PO_FILE)) |
| 489 | + with open(self.PO_FILE, 'r') as fp: |
| 490 | + po_contents = fp.read() |
| 491 | + self.assertMsgId('This literal should be included.', po_contents) |
| 492 | + self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html') |
498 | 493 |
|
499 | 494 |
|
500 | 495 | class CopyPluralFormsExtractorTests(ExtractorTests):
|
|
0 commit comments