def test_no_list_instantiation(self): with self.assertRaises(TypeError): typing.List() with self.assertRaises(TypeError): typing.List[T]() with self.assertRaises(TypeError): typing.List[int]()
def __init__(self, controller): self._controller = controller self._lock = threading.Lock() self._keys_to_services: typing.Dict[bytes, ClientServices.Service] = {} self._services_sorted: typing.List(ClientServices.Service) = [] self.RefreshServices() self._controller.sub(self, 'RefreshServices', 'notify_new_services_data')
def launch_test_with_mock_file(func: typing.Callable, file_content: str) -> unittest.mock.Mock: '''Takes a function and a file content and returns a Mock object which mimics our ModelGenerator's behaviour when calling the function with that filename in the correct `args` member.''' mock: unittest.mock.Mock = unittest.mock.Mock() mock.args.grammar: str = str() mock.args.assets: str = str() mock.args.verbose: bool = False mock.grammar: typing.Dict[str, typing.List(str)] = dict() mock.assets: typing.Dict[str, typing.List(str)] = dict() # Patch the `open` function so we can mock the file opening in `func` with unittest.mock.patch(f'builtins.open', unittest.mock.mock_open(read_data=file_content), create=True): # Give the mock as the `self` parameter to our function func(mock) return mock
class AppState: record_type: str = APP_STATE_RECORD_TYPE scratch_note: str = "" nodes: typing.List(Node) = attr.Factory(list) @classmethod def from_json_str(cls, json_str): json_obj = json.loads(json_str) return cls.from_json(json_obj) @classmethod def from_json(cls, json_obj): if not json_obj: return cls() return cattr.structure(json_obj, cls) def to_json(self): return cattr.unstructure(self) def to_json_str(self): return json.dumps(self.to_json())
def getFee(self, rate: float) -> typing.List(float): return [rate * 0.1, rate * 0.05]