[formatter] allow accessing 'util.NONE' via global '_nul'
This commit is contained in:
@@ -272,6 +272,12 @@ Replacement field names that are available in all format strings.
|
||||
<td><code>{_now:%Y-%m}</code></td>
|
||||
<td><code>2022-08</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>_nul</code></td>
|
||||
<td>Universal <code>null</code> value</td>
|
||||
<td><code>{date|_nul:%Y-%m}</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="2"><code>_lit</code></td>
|
||||
<td rowspan="2">String literals</td>
|
||||
|
||||
@@ -476,6 +476,7 @@ _GLOBALS = {
|
||||
"_env": lambda: os.environ,
|
||||
"_lit": lambda: _literal,
|
||||
"_now": datetime.datetime.now,
|
||||
"_nul": lambda: util.NONE,
|
||||
}
|
||||
_CONVERSIONS = {
|
||||
"l": str.lower,
|
||||
|
||||
@@ -351,6 +351,14 @@ class TestFormatter(unittest.TestCase):
|
||||
self.assertRegex(out1, r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d(\.\d+)?$")
|
||||
self.assertNotEqual(out1, out2)
|
||||
|
||||
def test_globals_nul(self):
|
||||
value = "None"
|
||||
|
||||
self._run_test("{_nul}" , value)
|
||||
self._run_test("{_nul[key]}" , value)
|
||||
self._run_test("{z|_nul}" , value)
|
||||
self._run_test("{z|_nul:%Y%m%s}", value)
|
||||
|
||||
def test_literals(self):
|
||||
value = "foo"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user