コード例 #1
0
 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]()
コード例 #2
0
    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')
コード例 #3
0
ファイル: lexer_test.py プロジェクト: bandang0/aamg
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
コード例 #4
0
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())
コード例 #5
0
ファイル: binance.py プロジェクト: drinks5/arbitrage
 def getFee(self, rate: float) -> typing.List(float):
     return [rate * 0.1, rate * 0.05]