mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Apply pylint's linting rules to bfxapi/tests/*.py.
This commit is contained in:
@@ -19,7 +19,7 @@ disable=
|
|||||||
|
|
||||||
max-line-length=130
|
max-line-length=130
|
||||||
|
|
||||||
good-names=id,on
|
good-names=id,on,pl,t,A,B,C,D,E,F
|
||||||
|
|
||||||
[TYPECHECK]
|
[TYPECHECK]
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ def suite():
|
|||||||
unittest.makeSuite(TestLabeler),
|
unittest.makeSuite(TestLabeler),
|
||||||
unittest.makeSuite(TestNotification),
|
unittest.makeSuite(TestNotification),
|
||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.TextTestRunner().run(suite())
|
unittest.TextTestRunner().run(suite())
|
||||||
|
|||||||
@@ -25,24 +25,24 @@ class TestLabeler(unittest.TestCase):
|
|||||||
self.assertListEqual(serializer.get_labels(), [ "A", "B", "C" ],
|
self.assertListEqual(serializer.get_labels(), [ "A", "B", "C" ],
|
||||||
msg="_Serializer::get_labels() should return the right list of labels.")
|
msg="_Serializer::get_labels() should return the right list of labels.")
|
||||||
|
|
||||||
with self.assertRaises(LabelerSerializerException,
|
with self.assertRaises(LabelerSerializerException,
|
||||||
msg="_Serializer should raise LabelerSerializerException if given fewer arguments than the serializer labels."):
|
msg="_Serializer should raise LabelerSerializerException if given fewer arguments than the serializer labels."):
|
||||||
serializer.parse(5, 65.0, "X")
|
serializer.parse(5, 65.0, "X")
|
||||||
|
|
||||||
def test_generate_recursive_serializer(self):
|
def test_generate_recursive_serializer(self):
|
||||||
@dataclass
|
@dataclass
|
||||||
class Outer(_Type):
|
class Outer(_Type):
|
||||||
A: int
|
A: int
|
||||||
B: float
|
B: float
|
||||||
C: "Middle"
|
C: "Middle"
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Middle(_Type):
|
class Middle(_Type):
|
||||||
D: str
|
D: str
|
||||||
E: "Inner"
|
E: "Inner"
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Inner(_Type):
|
class Inner(_Type):
|
||||||
F: bool
|
F: bool
|
||||||
|
|
||||||
inner = generate_labeler_serializer("Inner", Inner, ["F"])
|
inner = generate_labeler_serializer("Inner", Inner, ["F"])
|
||||||
@@ -53,4 +53,4 @@ class TestLabeler(unittest.TestCase):
|
|||||||
msg="_RecursiveSerializer should produce the right result.")
|
msg="_RecursiveSerializer should produce the right result.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -11,15 +11,19 @@ class TestNotification(unittest.TestCase):
|
|||||||
A: int
|
A: int
|
||||||
B: float
|
B: float
|
||||||
C: str
|
C: str
|
||||||
|
|
||||||
test = generate_labeler_serializer("Test", Test,
|
test = generate_labeler_serializer("Test", Test,
|
||||||
[ "A", "_PLACEHOLDER", "B", "_PLACEHOLDER", "C" ])
|
[ "A", "_PLACEHOLDER", "B", "_PLACEHOLDER", "C" ])
|
||||||
|
|
||||||
notification = _Notification[Test](test)
|
notification = _Notification[Test](test)
|
||||||
|
|
||||||
self.assertEqual(notification.parse(*[1675787861506, "test", None, None, [ 5, None, 65.0, None, "X" ], 0, "SUCCESS", "This is just a test notification."]),
|
actual = notification.parse(*[ 1675787861506, "test", None, None, [ 5, None, 65.0, None, "X" ], \
|
||||||
Notification[Test](1675787861506, "test", None, Test(5, 65.0, "X"), 0, "SUCCESS", "This is just a test notification."),
|
0, "SUCCESS", "This is just a test notification." ])
|
||||||
msg="_Notification should produce the right notification.")
|
|
||||||
|
expected = Notification[Test](1675787861506, "test", None, Test(5, 65.0, "X"),
|
||||||
|
0, "SUCCESS", "This is just a test notification.")
|
||||||
|
|
||||||
|
self.assertEqual(actual, expected, msg="_Notification should produce the right notification.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#pylint: disable=duplicate-code
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ..labeler import _Type
|
from ..labeler import _Type
|
||||||
@@ -7,11 +9,11 @@ from ..rest import serializers
|
|||||||
class TestRestSerializers(unittest.TestCase):
|
class TestRestSerializers(unittest.TestCase):
|
||||||
def test_rest_serializers(self):
|
def test_rest_serializers(self):
|
||||||
for serializer in map(serializers.__dict__.get, serializers.__serializers__):
|
for serializer in map(serializers.__dict__.get, serializers.__serializers__):
|
||||||
self.assertTrue(issubclass(serializer.klass, _Type),
|
self.assertTrue(issubclass(serializer.klass, _Type),
|
||||||
f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).")
|
f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).")
|
||||||
|
|
||||||
self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__),
|
self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__),
|
||||||
f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> must have matching labels and fields.")
|
f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> must have matching labels and fields.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#pylint: disable=duplicate-code
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ..labeler import _Type
|
from ..labeler import _Type
|
||||||
@@ -7,11 +9,11 @@ from ..websocket import serializers
|
|||||||
class TestWebsocketSerializers(unittest.TestCase):
|
class TestWebsocketSerializers(unittest.TestCase):
|
||||||
def test_websocket_serializers(self):
|
def test_websocket_serializers(self):
|
||||||
for serializer in map(serializers.__dict__.get, serializers.__serializers__):
|
for serializer in map(serializers.__dict__.get, serializers.__serializers__):
|
||||||
self.assertTrue(issubclass(serializer.klass, _Type),
|
self.assertTrue(issubclass(serializer.klass, _Type),
|
||||||
f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).")
|
f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).")
|
||||||
|
|
||||||
self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__),
|
self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__),
|
||||||
f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> must have matching labels and fields.")
|
f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> must have matching labels and fields.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ class BfxWebsocketBucket:
|
|||||||
|
|
||||||
self.handler = PublicChannelsHandler(event_emitter=self.event_emitter)
|
self.handler = PublicChannelsHandler(event_emitter=self.event_emitter)
|
||||||
|
|
||||||
#pylint: disable-next=unused-argument
|
async def connect(self):
|
||||||
async def connect(self, index):
|
|
||||||
reconnection = False
|
reconnection = False
|
||||||
|
|
||||||
async for websocket in websockets.connect(self.host):
|
async for websocket in websockets.connect(self.host):
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class BfxWebsocketClient:
|
|||||||
for index in range(connections):
|
for index in range(connections):
|
||||||
self.buckets += [BfxWebsocketBucket(self.host, self.event_emitter, self.on_open_events[index])]
|
self.buckets += [BfxWebsocketBucket(self.host, self.event_emitter, self.on_open_events[index])]
|
||||||
|
|
||||||
tasks = [ bucket.connect(index) for index, bucket in enumerate(self.buckets) ]
|
tasks = [ bucket.connect() for bucket in self.buckets ]
|
||||||
|
|
||||||
tasks.append(self.__connect())
|
tasks.append(self.__connect())
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#pylint: disable=invalid-name,redefined-builtin,too-many-arguments
|
#pylint: disable=redefined-builtin,too-many-arguments
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
#pylint: disable-next=wildcard-import,unused-wildcard-import
|
||||||
from typing import *
|
from typing import *
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from .. labeler import _Type
|
#pylint: disable-next=unused-import
|
||||||
from .. notification import Notification
|
from .. notification import Notification
|
||||||
|
|
||||||
|
from .. labeler import _Type
|
||||||
|
|
||||||
from ..utils.json_encoder import JSON
|
from ..utils.json_encoder import JSON
|
||||||
|
|
||||||
#region Type hinting for Websocket Public Channels
|
#region Type hinting for Websocket Public Channels
|
||||||
@@ -40,43 +44,43 @@ class FundingCurrencyTicker(_Type):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TradingPairTrade(_Type):
|
class TradingPairTrade(_Type):
|
||||||
id: int
|
id: int
|
||||||
mts: int
|
mts: int
|
||||||
amount: float
|
amount: float
|
||||||
price: float
|
price: float
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FundingCurrencyTrade(_Type):
|
class FundingCurrencyTrade(_Type):
|
||||||
id: int
|
id: int
|
||||||
mts: int
|
mts: int
|
||||||
amount: float
|
amount: float
|
||||||
rate: float
|
rate: float
|
||||||
period: int
|
period: int
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TradingPairBook(_Type):
|
class TradingPairBook(_Type):
|
||||||
price: float
|
price: float
|
||||||
count: int
|
count: int
|
||||||
amount: float
|
amount: float
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FundingCurrencyBook(_Type):
|
class FundingCurrencyBook(_Type):
|
||||||
rate: float
|
rate: float
|
||||||
period: int
|
period: int
|
||||||
count: int
|
count: int
|
||||||
amount: float
|
amount: float
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TradingPairRawBook(_Type):
|
class TradingPairRawBook(_Type):
|
||||||
order_id: int
|
order_id: int
|
||||||
price: float
|
price: float
|
||||||
amount: float
|
amount: float
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FundingCurrencyRawBook(_Type):
|
class FundingCurrencyRawBook(_Type):
|
||||||
offer_id: int
|
offer_id: int
|
||||||
period: int
|
period: int
|
||||||
rate: float
|
rate: float
|
||||||
amount: float
|
amount: float
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -154,14 +158,14 @@ class Position(_Type):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Trade(_Type):
|
class Trade(_Type):
|
||||||
id: int
|
id: int
|
||||||
symbol: str
|
symbol: str
|
||||||
mts_create: int
|
mts_create: int
|
||||||
order_id: int
|
order_id: int
|
||||||
exec_amount: float
|
exec_amount: float
|
||||||
exec_price: float
|
exec_price: float
|
||||||
order_type: str
|
order_type: str
|
||||||
order_price: float
|
order_price: float
|
||||||
maker:int
|
maker:int
|
||||||
fee: Optional[float]
|
fee: Optional[float]
|
||||||
fee_currency: Optional[str]
|
fee_currency: Optional[str]
|
||||||
@@ -238,4 +242,4 @@ class Balance(_Type):
|
|||||||
aum: float
|
aum: float
|
||||||
aum_net: float
|
aum_net: float
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user