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

Unittest 總是遇到 AssertError #97

Closed
LorneWu opened this issue Oct 11, 2021 · 3 comments
Closed

Unittest 總是遇到 AssertError #97

LorneWu opened this issue Oct 11, 2021 · 3 comments

Comments

@LorneWu
Copy link

LorneWu commented Oct 11, 2021

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

@LorneWu
Copy link
Author

LorneWu commented Oct 11, 2021

我想嘗試先更新

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

@LorneWu
Copy link
Author

LorneWu commented Oct 11, 2021

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

LorneWu added a commit to LorneWu/twstock that referenced this issue Oct 11, 2021
@mlouielu
Copy link
Owner

Fixed in #125, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants