本文整理汇总了Python中Controller.Controller.do_serial_save方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.do_serial_save方法的具体用法?Python Controller.do_serial_save怎么用?Python Controller.do_serial_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller.Controller
的用法示例。
在下文中一共展示了Controller.do_serial_save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_SerialSave_01
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import do_serial_save [as 别名]
def test_SerialSave_01(self, mock_isfile, mock_open):
"""
Saving a RecordCollection with 10 Records
"""
def doDump():
doDump.theDump = theDumpStream.getvalue()
theDumpStream = BytesIO()
theDumpStream.close = Mock(side_effect=doDump)
# So that it is know that file does not exist
mock_isfile.return_value = False
mock_open.return_value = theDumpStream
theController = Controller(TestView.TestView(), None)
# add 10 Records, reset view log, then serial save
self._addSomeRecordsViaController(theController, 10)
TestView.clearLog()
theController.do_serial_save("")
# Part 1: Check contents of theDumpStream
# theDump = theDumpStream.getvalue()
expectedRecords = 10
fromDump = pickle.load(BytesIO(doDump.theDump))
actualRecords = len(fromDump.getAllRecords())
self.assertEqual(expectedRecords, actualRecords)
# Part 2: Check no show() messages on theLog
expectedLog = 0
actualLog = len(TestView.theLog)
self.assertEqual(expectedLog, actualLog)
示例2: test_SerialSave_03
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import do_serial_save [as 别名]
def test_SerialSave_03(self, mock_isfile, mock_open):
"""
Handles IOError
- Because the IOError message is expected to be determined by the
IOError constructor, the message will be randomised
"""
message = str(random.randrange(100))
mock_isfile.return_value = False
mock_open.side_effect = IOError(message)
theController = Controller(TestView.TestView(), None)
TestView.clearLog()
theController.do_serial_save("")
expectedShow = "EXCEPTION: {}\n".format(message)
actualShow = TestView.theLog[0]
self.assertEqual(expectedShow, actualShow)
示例3: test_SerialSave_02
# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import do_serial_save [as 别名]
def test_SerialSave_02(self, mock_isfile, mock_open):
"""
Ensure that a serial save does not happen when file exists
- isfile will return true
- Ensure open does not get called: If it does an error will be raised
"""
mock_isfile.return_value = True
mock_open.side_effect = AssertionError()
theController = Controller(TestView.TestView(), None)
TestView.clearLog()
theController.do_serial_save("")
expectedShow = "Will not overwrite an existing file\nPlease, enter a \
new file when using serial_save\n"
actualShow = TestView.theLog[0]
self.assertEqual(expectedShow, actualShow)