全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 python论坛
1762 1
2020-09-22
CDA人工智能学院致力于以优质的人工智能在线教育资源助力学员的DT职业梦想!课程内容涵盖数据分析机器学习深度学习人工智能tensorFlowPyTorch知识图谱等众多核心技术及行业案例,让每一个学员都可以在线灵活学习,快速掌握AI时代的前沿技术。PS:私信我即可获取《银牌会员》1个月免费试听机会

本文实例讲述了python自动化测试之连接几组测试包的方法,分享给大家供大家参考。具体方法如下:

具体代码如下:   
class RomanNumeralConverter(object):
  def __init__(self):
    self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10, "V":5, "I":1}
      
  def convert_to_decimal(self, roman_numeral):
    val = 0
    for char in roman_numeral:
      val += self.digit_map[char]
    return val
   
import unittest
class RomanNumeralConverterTest(unittest.TestCase):
  def setUp(self):
    self.cvt = RomanNumeralConverter()
      
  def test_parsing_millenia(self):
    self.assertEquals(1000, self.cvt.convert_to_decimal("M"))
      
  def test_parsing_century(self):
    self.assertEquals(100, self.cvt.convert_to_decimal("C"))
      
class RomanNumeralConverterCombo(unittest.TestCase):
  def setUp(self):
    self.cvt = RomanNumeralConverter()
      
  def test_multi_millenia(self):
    self.assertEquals(4000, self.cvt.convert_to_decimal("MMMM"))
      
  def test_add_up(self):
    self.assertEquals(2010, self.cvt.convert_to_decimal("MMX"))
      
if __name__ == "__main__":
  suite1 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterTest)
  suite2 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterCombo)
  suite = unittest.TestSuite([suite1, suite2])
  unittest.TextTestRunner(verbosity=2).run(suite)

运行结果如下:   
test_parsing_century (__main__.RomanNumeralConverterTest) ... ok
test_parsing_millenia (__main__.RomanNumeralConverterTest) ... ok
test_add_up (__main__.RomanNumeralConverterCombo) ... ok
test_multi_millenia (__main__.RomanNumeralConverterCombo) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.032s

OK

本文实例与前面几篇文章的内容基本一致,只在main中有些不同:
suite1 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterTest)
  suite2 = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterCombo)
  suite = unittest.TestSuite([suite1, suite2])
  unittest.TextTestRunner(verbosity=2).run(suite)
希望本文所述对大家的Python程序设计有所帮助。

0D04CBB8996CB009643B8D6FD844F0C0.jpg

关注“CDA人工智能学院”,回复“录播”获取更多人工智能精选直播视频!


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2024-7-17 12:07:35
CDA level | 最牛复习资料:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
【更新中】CDA level | 最全备考攻略:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
最全CDA认证考试1级辅导资料:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
CDA持证人阿涛一级教材串讲系列资料:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
CDA 一级2024最新模拟题一(全网最详细有答案):https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
CDA教材《精益业务数据分析》试读下载:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
数据分析高频面试50题下载:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
35个数据分析模型下载:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
【可下载】2024数字化人才指数报告:https://edu.cda.cn/group/4/threa ... ce=bbs-cda-exam-css
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群