Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unittest AssertError issue (#97) #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_mock_get_stock_info_will_work(self):
def test_mock_get_stock_info_raw_data(self):
self.assertCountEqual(
mock.get_stock_info('2330').keys(),
['msgArray', 'userDelay', 'rtmessage', 'referer', 'queryTime', 'rtcode'])
['msgArray', 'referer', 'userDelay', 'rtcode', 'queryTime', 'rtmessage', 'exKey', 'cachedAlive'])

def test_mock_get_stock_info_msgarray(self):
self.assertEqual(mock.get_stock_info('2330')['msgArray'][0]['c'], '2330')
Expand Down
8 changes: 5 additions & 3 deletions test/test_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def test_mock_one_stock_id(self):

self.assertTrue(s['success'])
self.assertEqual(s['info']['code'], '2330')
self.assertEqual(s['realtime']['latest_trade_price'], '214.50')
self.assertEqual(s['realtime']['best_bid_price'],
['214.00', '213.50', '213.00', '212.50', '212.00'])
# match 100 ~ 999
self.assertRegex(s['realtime']['latest_trade_price'], "[0-9]{3}\.[0-9]+")
for index in range(5):
# match 100 ~ 999
self.assertRegex(s['realtime']['best_bid_price'][index], "[0-9]{3}\.[0-9]+")

@unittest.skip('Dont want to fix this, is about the code in realtime')
def test_mock_multiple_stock_id(self):
Expand Down
226 changes: 179 additions & 47 deletions twstock/mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,185 @@


TSE_2330_TW = ["""
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999778918", "tk1":
"2330.tw_tse_20170724_B_9999777950", "tlong": "1500860849000", "f":
"853_1193_972_1209_817_", "ex": "tse", "g": "1221_1530_817_1038_1193_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "264564", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5094", "u": "235.00", "t": "09:47:29", "s":
"1", "pz": "213.50", "tv": "1", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.50", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:47:30", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 2065, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 204322}, "rtcode": "0000"}
""", """
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999766224", "tk1":
"2330.tw_tse_20170724_B_9999765954", "tlong": "1500861105000", "f":
"1059_1079_1014_1229_907_", "ex": "tse", "g": "1455_1598_797_1019_1134_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "778472", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5217", "u": "235.00", "t": "09:51:45", "s":
"0", "pz": "213.50", "tv": "1", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.50", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:51:48", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 2055, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 130895}, "rtcode": "0000"}
""", """
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999760446", "tk1":
"2330.tw_tse_20170724_B_9999759382", "tlong": "1500861243000", "f":
"1034_1028_1009_1253_933_", "ex": "tse", "g": "1466_1625_798_987_1117_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "962863", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5268", "u": "235.00", "t": "09:54:03", "s":
"0", "pz": "213.50", "tv": "3", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.00", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:54:10", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 1602, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 119518}, "rtcode": "0000"}
{
"cachedAlive": 23580,
"exKey": "if_tse_2330.tw_zh-tw.null",
"msgArray": [
{
"a": "580.0000_581.0000_582.0000_583.0000_584.0000_",
"b": "579.0000_578.0000_577.0000_576.0000_575.0000_",
"bp": "0",
"c": "2330",
"ch": "2330.tw",
"d": "20211007",
"ex": "tse",
"f": "596_491_841_792_450_",
"fv": "92",
"g": "13_187_364_633_530_",
"h": "582.0000",
"i": "24",
"ip": "0",
"it": "12",
"l": "572.0000",
"mt": "000000",
"n": "\u53f0\u7a4d\u96fb",
"nf": "\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"o": "575.0000",
"oa": "581.0000",
"ob": "580.0000",
"ot": "14:30:00",
"ov": "56054",
"oz": "580.0000",
"p": "0",
"ps": "3391",
"pz": "580.0000",
"s": "3403",
"t": "13:30:00",
"tlong": "1633588200000",
"ts": "0",
"tv": "3403",
"u": "628.0000",
"v": "27785",
"w": "514.0000",
"y": "571.0000",
"z": "580.0000"
}
],
"queryTime": {
"sessionFromTime": -1,
"sessionLatestTime": -1,
"sessionStr": "UserSession",
"showChart": false,
"stockInfo": 160242,
"stockInfoItem": 2030,
"sysDate": "20211008",
"sysTime": "06:42:20"
},
"referer": "",
"rtcode": "0000",
"rtmessage": "OK",
"userDelay": 5000
}
""","""
{
"cachedAlive": 17912,
"exKey": "if_tse_2330.tw_zh-tw.null",
"msgArray": [
{
"a": "575.0000_576.0000_577.0000_578.0000_579.0000_",
"b": "574.0000_573.0000_572.0000_571.0000_570.0000_",
"bp": "0",
"c": "2330",
"ch": "2330.tw",
"d": "20211008",
"ex": "tse",
"f": "109_521_423_231_426_",
"fv": "43",
"g": "272_743_539_437_1929_",
"h": "583.0000",
"i": "24",
"ip": "0",
"it": "12",
"l": "573.0000",
"mt": "000000",
"n": "\u53f0\u7a4d\u96fb",
"nf": "\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"o": "582.0000",
"oa": "579.0000",
"ob": "578.0000",
"ot": "14:30:00",
"ov": "32079",
"oz": "578.0000",
"p": "0",
"ps": "2797",
"pz": "575.0000",
"s": "2799",
"t": "13:30:00",
"tlong": "1633674600000",
"ts": "0",
"tv": "2799",
"u": "638.0000",
"v": "18204",
"w": "522.0000",
"y": "580.0000",
"z": "575.0000"
}
],
"queryTime": {
"sessionFromTime": -1,
"sessionLatestTime": -1,
"sessionStr": "UserSession",
"showChart": false,
"stockInfo": 70537,
"stockInfoItem": 124,
"sysDate": "20211011",
"sysTime": "13:54:37"
},
"referer": "",
"rtcode": "0000",
"rtmessage": "OK",
"userDelay": 5000
}
""","""
{
"cachedAlive": 262,
"exKey": "if_tse_2330.tw_zh-tw.null",
"msgArray": [
{
"a": "575.0000_576.0000_577.0000_578.0000_579.0000_",
"b": "574.0000_573.0000_572.0000_571.0000_570.0000_",
"bp": "0",
"c": "2330",
"ch": "2330.tw",
"d": "20211008",
"ex": "tse",
"f": "109_521_423_231_426_",
"fv": "43",
"g": "272_743_539_437_1929_",
"h": "583.0000",
"i": "24",
"ip": "0",
"it": "12",
"l": "573.0000",
"mt": "000000",
"n": "\u53f0\u7a4d\u96fb",
"nf": "\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"o": "582.0000",
"oa": "579.0000",
"ob": "578.0000",
"ot": "14:30:00",
"ov": "32079",
"oz": "578.0000",
"p": "0",
"ps": "2797",
"pz": "575.0000",
"s": "2799",
"t": "13:30:00",
"tlong": "1633674600000",
"ts": "0",
"tv": "2799",
"u": "638.0000",
"v": "18204",
"w": "522.0000",
"y": "580.0000",
"z": "575.0000"
}
],
"queryTime": {
"sessionFromTime": -1,
"sessionLatestTime": -1,
"sessionStr": "UserSession",
"showChart": false,
"stockInfo": 287352,
"stockInfoItem": 1214,
"sysDate": "20211011",
"sysTime": "13:56:35"
},
"referer": "",
"rtcode": "0000",
"rtmessage": "OK",
"userDelay": 5000
}
"""]


Expand Down