MCPcopy
hub / github.com/django/django / _assertPoLocComment

Method _assertPoLocComment

tests/i18n/test_extraction.py:64–93  ·  view source on GitHub ↗
(
        self, assert_presence, po_filename, line_number, *comment_parts
    )

Source from the content-addressed store, hash-verified

62 return self.assertTrue(not re.search("^msgid %s" % msgid, s, re.MULTILINE))
63
64 def _assertPoLocComment(
65 self, assert_presence, po_filename, line_number, *comment_parts
66 ):
67 with open(po_filename) as fp:
68 po_contents = fp.read()
69 if os.name == "nt":
70 # #: .\path\to\file.html:123
71 cwd_prefix = "%s%s" % (os.curdir, os.sep)
72 else:
73 # #: path/to/file.html:123
74 cwd_prefix = ""
75
76 path = os.path.join(cwd_prefix, *comment_parts)
77 parts = [path]
78
79 if isinstance(line_number, str):
80 line_number = self._get_token_line_number(path, line_number)
81 if line_number is not None:
82 parts.append(":%d" % line_number)
83
84 needle = "".join(parts)
85 pattern = re.compile(r"^\#\:.*" + re.escape(needle), re.MULTILINE)
86 if assert_presence:
87 return self.assertRegex(
88 po_contents, pattern, '"%s" not found in final .po file.' % needle
89 )
90 else:
91 return self.assertNotRegex(
92 po_contents, pattern, '"%s" shouldn\'t be in final .po file.' % needle
93 )
94
95 def _get_token_line_number(self, path, token):
96 with open(path) as f:

Calls 5

readMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected