Coverage for cc_modules/cc_testhelpers.py : 27%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_testhelpers.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
27**Helper functions used during testing.**
29"""
31from typing import List, Type
34def class_attribute_names(cls: Type,
35 exclude_underscore: bool = True,
36 exclude_double_underscore: bool = True) -> List[str]:
37 """
38 When given a class, returns the names of all its attributes, by default
39 excluding those starting with single and double underscores.
41 Used in particular to enumerate constants provided within a class.
42 """
43 attrs = [] # type: List[str]
44 for x in cls.__dict__.keys():
45 if exclude_underscore and x.startswith("_"):
46 continue
47 if exclude_double_underscore and x.startswith("__"):
48 continue
49 attrs.append(x)
50 return attrs