Debian Codegraph @

test/units/utils/test_isidentifier.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright: (c) 2020 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import pytest
8
9 from ansible.utils.vars import isidentifier
10
11
12 # Originally posted at: http://stackoverflow.com/a/29586366
13
14
15 @pytest.mark.parametrize(
16 "identifier", [
17 "foo", "foo1_23",
18 ]
19 )
20 def test_valid_identifier(identifier):
21 assert isidentifier(identifier)
22
23
24 @pytest.mark.parametrize(
25 "identifier", [
26 "pass", "foo ", " foo", "1234", "1234abc", "", " ", "foo bar", "no-dashed-names-for-you",
27 "True", "False", "None"
28 ]
29 )
30 def test_invalid_identifier(identifier):
31 assert not isidentifier(identifier)
32
33
34 def test_non_ascii():
35 """In Python 3 non-ascii characters are allowed as opposed to Python 2. The
36 isidentifier method ensures that those are treated as keywords on both
37 Python 2 and 3.
38 """
39 assert not isidentifier("křížek")