Fix & extend unit tests
This commit is contained in:
1 parent
68f4ecefb0
commit
e224b0ac71
1 file changed
+28
@@ -6,6 +6,7 @@ __copyright__ = "Copyright (C) 2016 The OctoPrint Project - Released under terms
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
import ddt
|
||||
|
||||
import os
|
||||
import time
|
||||
@@ -14,9 +15,11 @@ from collections import namedtuple, OrderedDict
|
||||
_stat = namedtuple("StatResult", "st_size, st_ctime, st_mtime")
|
||||
_entry = namedtuple("DirEntry", "name, path, is_file, is_dir, stat")
|
||||
|
||||
import octoprint.plugin
|
||||
import octoprint.settings
|
||||
import octoprint.timelapse
|
||||
|
||||
@ddt.ddt
|
||||
class TimelapseTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -27,10 +30,35 @@ class TimelapseTest(unittest.TestCase):
|
||||
self.settings = mock.create_autospec(octoprint.settings.Settings)
|
||||
self.settings_getter.return_value = self.settings
|
||||
|
||||
self.plugin_manager_patcher = mock.patch("octoprint.timelapse.plugin_manager")
|
||||
self.plugin_manager_getter = self.plugin_manager_patcher.start()
|
||||
|
||||
self.plugin_manager = mock.create_autospec(octoprint.plugin.PluginManager)
|
||||
self.plugin_manager_getter.return_value = self.plugin_manager
|
||||
|
||||
def extension_factory(*args, **kwargs):
|
||||
return ["gif"]
|
||||
hooks = dict(test=extension_factory)
|
||||
self.plugin_manager.get_hooks.return_value = hooks
|
||||
|
||||
self.now = time.time()
|
||||
|
||||
def cleanUp(self):
|
||||
self.settings_patcher.stop()
|
||||
self.plugin_manager_patcher.stop()
|
||||
|
||||
@ddt.data(
|
||||
("test.mpg", True),
|
||||
("test.dat", False),
|
||||
("test.gif", True)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_valid_timelapse(self, input, expected):
|
||||
## test
|
||||
actual = octoprint.timelapse.valid_timelapse(input)
|
||||
|
||||
## verify
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@mock.patch("os.remove")
|
||||
@mock.patch("octoprint.timelapse.scandir")
|
||||
|
||||
Reference in new issue
Block a user