1import inspect
2import sys
3
4
5def is_last_char_upper(string: str) -> bool:
6 if not string:
7 return False
8
9 for i in range(len(string) - 1, -1, -1):
10 if string[i].isalpha():
11 return isupper(string[i])
12
13 return False
14
15
16def isupper(char: str) -> bool:
17 return "A" <= char <= "Z"
18
19
20def has_consecutive_vowels(string: str) -> bool:
21 vowels = "aeiou"
22 count = 0
23 for char in string:
24 if char in vowels:
25 count += 1
26 if count > 3:
27 return True
28 else:
29 count = 0
30 return False
31
32
33class BridgeKeeper:
34 def __init__(self, module_name: str):
35 self.object = sys.modules[module_name]
36
37 def __getattr__(self, to_access):
38 attr = getattr(self.object, to_access)
39
40 if self.passes_all_tests(attr):
41 return attr
42
43 raise AttributeError(to_access)
44
45 def has_valid_name(self, object):
46 if not hasattr(object, "__name__"):
47 return False
48
49 name = object.__name__
50
51 return isupper(name[0])
52
53 def get_doc_params(self, string):
54 if string is None:
55 return []
56
57 params = string.find("Parameters\n----------")
58 if params == -1:
59 return []
60
61 params = string[params + len("Parameters\n----------") :]
62
63 end = params.find("\n\n")
64 if end != -1:
65 params = params[:end]
66
67 params = params.splitlines()
68 names = list()
69 for param in params:
70 name, _, _ = param.partition(":")
71 names.append(name)
72
73 return names
74
75 def has_valid_quest(self, object):
76 if not callable(object):
77 return False
78
79 arguments_passed = inspect.getfullargspec(object).args
80 docstring = self.get_doc_params(inspect.getdoc(object))
81
82 for argument in arguments_passed:
83 if docstring is None or argument not in docstring:
84 return False
85
86 return True
87
88 def has_valid_secret_question(self, obj):
89 attributes = dir(obj)
90
91 for attr in attributes:
92 not_dunder = True
93 no_three_consecutive_vowels = False
94 last_char_upper = False
95 if attr.startswith("__") and attr.endswith("__"):
96 not_dunder = False
97
98 if not has_consecutive_vowels(attr):
99 no_three_consecutive_vowels = True
100
101 if is_last_char_upper(attr):
102 last_char_upper = True
103
104 if not_dunder and no_three_consecutive_vowels and last_char_upper:
105 return True
106
107 return False
108
109 def passes_all_tests(self, object):
110 return (
111 self.has_valid_name(object)
112 and self.has_valid_quest(object)
113 and self.has_valid_secret_question(object)
114 )
115
116 def __enter__(self):
117 return self
118
119 def __exit__(self, exc_type, exc, tb):
120 return False
EEEEEEEEEEEEEEEEEEEEEEEEE
======================================================================
ERROR: test_allows_attribute_whose_last_letter_is_uppercase_but_name_continues (test.TestBridgeKeeper.test_allows_attribute_whose_last_letter_is_uppercase_but_name_continues)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 54, in test_allows_attribute_whose_last_letter_is_uppercase_but_name_continues
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_callable_instance (test.TestBridgeKeeper.test_allows_callable_instance)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 85, in test_allows_callable_instance
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_dict_typed_parameter (test.TestBridgeKeeper.test_allows_dict_typed_parameter)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 67, in test_allows_dict_typed_parameter
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_multi_argument_union_bonus_case (test.TestBridgeKeeper.test_allows_multi_argument_union_bonus_case)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 94, in test_allows_multi_argument_union_bonus_case
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_set_typed_parameter (test.TestBridgeKeeper.test_allows_set_typed_parameter)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 76, in test_allows_set_typed_parameter
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_third_answer_name_with_trailing_double_underscores_if_not_dunder (test.TestBridgeKeeper.test_allows_third_answer_name_with_trailing_double_underscores_if_not_dunder)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 63, in test_allows_third_answer_name_with_trailing_double_underscores_if_not_dunder
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_third_answer_with_single_uppercase_letter_name (test.TestBridgeKeeper.test_allows_third_answer_with_single_uppercase_letter_name)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 116, in test_allows_third_answer_with_single_uppercase_letter_name
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_union_typed_parameter (test.TestBridgeKeeper.test_allows_union_typed_parameter)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 16, in test_allows_union_typed_parameter
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_valid_function (test.TestBridgeKeeper.test_allows_valid_function)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 8, in test_allows_valid_function
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_zero_arg_callable_when_parameters_block_is_missing (test.TestBridgeKeeper.test_allows_zero_arg_callable_when_parameters_block_is_missing)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 12, in test_allows_zero_arg_callable_when_parameters_block_is_missing
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_allows_zero_arg_callable_with_missing_docstring (test.TestBridgeKeeper.test_allows_zero_arg_callable_with_missing_docstring)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_allows_zero_arg_callable_with_missing_docstring
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_ignores_parameter_like_lines_outside_parameters_block (test.TestBridgeKeeper.test_ignores_parameter_like_lines_outside_parameters_block)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 36, in test_ignores_parameter_like_lines_outside_parameters_block
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_callable_when_parameter_names_do_not_match (test.TestBridgeKeeper.test_rejects_callable_when_parameter_names_do_not_match)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 58, in test_rejects_callable_when_parameter_names_do_not_match
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_callable_without_valid_third_answer (test.TestBridgeKeeper.test_rejects_callable_without_valid_third_answer)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 31, in test_rejects_callable_without_valid_third_answer
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_dict_when_callable_does_not_work_with_documented_key_and_value_types (test.TestBridgeKeeper.test_rejects_dict_when_callable_does_not_work_with_documented_key_and_value_types)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 89, in test_rejects_dict_when_callable_does_not_work_with_documented_key_and_value_types
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_docstring_with_arity_mismatch (test.TestBridgeKeeper.test_rejects_docstring_with_arity_mismatch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 45, in test_rejects_docstring_with_arity_mismatch
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_docstring_with_parameter_order_mismatch (test.TestBridgeKeeper.test_rejects_docstring_with_parameter_order_mismatch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 40, in test_rejects_docstring_with_parameter_order_mismatch
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_list_when_callable_does_not_work_with_documented_element_type (test.TestBridgeKeeper.test_rejects_list_when_callable_does_not_work_with_documented_element_type)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 101, in test_rejects_list_when_callable_does_not_work_with_documented_element_type
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_missing_parameters_block_when_callable_requires_arguments (test.TestBridgeKeeper.test_rejects_missing_parameters_block_when_callable_requires_arguments)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 80, in test_rejects_missing_parameters_block_when_callable_requires_arguments
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_non_callable_object (test.TestBridgeKeeper.test_rejects_non_callable_object)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 26, in test_rejects_non_callable_object
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_object_with_lowercase_name (test.TestBridgeKeeper.test_rejects_object_with_lowercase_name)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 21, in test_rejects_object_with_lowercase_name
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_set_when_callable_does_not_work_with_documented_element_type (test.TestBridgeKeeper.test_rejects_set_when_callable_does_not_work_with_documented_element_type)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 111, in test_rejects_set_when_callable_does_not_work_with_documented_element_type
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_third_answer_with_four_consecutive_uppercase_vowels (test.TestBridgeKeeper.test_rejects_third_answer_with_four_consecutive_uppercase_vowels)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 120, in test_rejects_third_answer_with_four_consecutive_uppercase_vowels
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_tuple_when_callable_does_not_work_with_documented_element_type (test.TestBridgeKeeper.test_rejects_tuple_when_callable_does_not_work_with_documented_element_type)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 106, in test_rejects_tuple_when_callable_does_not_work_with_documented_element_type
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
======================================================================
ERROR: test_rejects_union_when_callable_does_not_support_all_union_branches (test.TestBridgeKeeper.test_rejects_union_when_callable_does_not_support_all_union_branches)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 71, in test_rejects_union_when_callable_does_not_support_all_union_branches
with BridgeKeeper("bridgekeeper_cases") as filtered:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 35, in __init__
self.object = sys.modules[module_name]
~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'bridgekeeper_cases'
----------------------------------------------------------------------
Ran 25 tests in 0.007s
FAILED (errors=25)