Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion appium/common/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def extract_const_attributes(cls: type) -> dict[str, Any]:
Returns:
dict with constants attributes and values in the class
"""
return {attr: value for attr, value in vars(cls).items() if not callable(getattr(cls, attr)) and attr.isupper()}
return {
attr: value
for attr, value in vars(cls).items()
if attr.isupper() and not callable(value) and not isinstance(value, classmethod)
}


def library_version() -> str:
Expand Down
42 changes: 42 additions & 0 deletions test/unit/common/helper_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

# 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 appium.common.helper import extract_const_attributes


class DummyConstants:
VAL1 = 100
VAL2 = 'test_value'
_PRIVATE = 'private_const'
lower_case = 'ignored'

@classmethod
def CLASS_METHOD(cls):
pass

@staticmethod
def STATIC_METHOD():
pass

def instance_method(self):
pass


def test_extract_const_attributes():
constants = extract_const_attributes(DummyConstants)
assert constants == {
'VAL1': 100,
'VAL2': 'test_value',
'_PRIVATE': 'private_const',
}