mlouielu / twstock

台灣股市股票價格擷取 (含即時股票資訊) - Taiwan Stock Opendata with realtime

Home Page:http://twstock.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unittest 總是遇到 AssertError

LorneWu opened this issue · comments

Unittest 總是遇到 AssertError

image-20211011154753854

我看起來是 'http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch={stock_id}&_={time}' api 格式有變

原先是 dict_keys(['msgArray', 'userDelay', 'rtmessage', 'referer', 'queryTime', 'rtcode'])

後來新增了一些欄位 dict_keys(['msgArray', 'referer', 'userDelay', 'rtcode', 'queryTime', 'rtmessage', 'exKey', 'cachedAlive'])

所以導致

AssertionError: Element counts were not equal:
First has 1, Second has 0:  'exKey'
First has 1, Second has 0:  'cachedAlive'

Reference link :

https://travis-ci.org/github/mlouielu/twstock/jobs/764044874
https://travis-ci.org/github/mlouielu/twstock/jobs/772273350

我想嘗試先更新

self.assertCountEqual(
    mock.get_stock_info('2330').keys(),
    ['msgArray', 'referer', 'userDelay', 'rtcode', 'queryTime', 'rtmessage', 'exKey', 'cachedAlive'])

image
https://app.travis-ci.com/github/LorneWu/twstock/jobs/542408327
遇到這個問題,我看起來是去比較 最新的價格是否是 214.50

  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]+")

Fixed in #125, thanks.