forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobottypes.py
More file actions
57 lines (44 loc) · 1.95 KB
/
Copy pathrobottypes.py
File metadata and controls
57 lines (44 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2008-2015 Nokia Networks
# Copyright 2016- Robot Framework Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .platform import PY2
if PY2:
from .robottypes2 import (is_bytes, is_dict_like, is_integer, is_list_like,
is_number, is_string, is_unicode, type_name)
unicode = unicode
else:
from .robottypes3 import (is_bytes, is_dict_like, is_integer, is_list_like,
is_number, is_string, is_unicode, type_name)
unicode = str
TRUE_STRINGS = {'TRUE', 'YES', 'ON', '1'}
FALSE_STRINGS = {'FALSE', 'NO', 'OFF', '0', 'NONE', ''}
def is_truthy(item):
"""Returns `True` or `False` depending is the item considered true or not.
Validation rules:
- If the value is a string, it is considered false if it is `'FALSE'`,
`'NO'`, `'OFF'`, `'0'`, `'NONE'` or `''`, case-insensitively.
Considering `'NONE'` false is new in RF 3.0.3 and considering `'OFF'`
and `'0'` false is new in RF 3.1.
- Other strings are considered true.
- Other values are handled by using the standard `bool()` function.
Designed to be used also by external test libraries that want to handle
Boolean values similarly as Robot Framework itself. See also
:func:`is_falsy`.
"""
if is_string(item):
return item.upper() not in FALSE_STRINGS
return bool(item)
def is_falsy(item):
"""Opposite of :func:`is_truthy`."""
return not is_truthy(item)