diff --git a/tests/tests_abstract.py b/tests/tests_abstract.py index 7dc4bdbda982349720edf4bbe0b429002dd980bb..552b05201e8848d0dc4102089f398cb2dad7b513 100644 --- a/tests/tests_abstract.py +++ b/tests/tests_abstract.py @@ -4,6 +4,17 @@ import unittest import pyinsane2 +def get_devices(): + '''Return devices, perhaps after creating a test device.''' + devices = pyinsane2.get_devices() + if len(devices) == 0: + # if there are no devices found, create a virtual device. + # see sane-test(5) and /etc/sane.d/test.conf + pyinsane2.Scanner("test").scan() + devices = pyinsane2.get_devices() + return devices + + class TestSaneGetDevices(unittest.TestCase): module = None @@ -11,12 +22,7 @@ class TestSaneGetDevices(unittest.TestCase): pyinsane2.init() def test_get_devices(self): - devices = pyinsane2.get_devices() - if len(devices) == 0: - # if there are no devices found, create a virtual device. - # see sane-test(5) and /etc/sane.d/test.conf - pyinsane2.Scanner("test")._open() - devices = pyinsane2.get_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) def tearDown(self): @@ -28,7 +34,7 @@ class TestSaneOptions(unittest.TestCase): def setUp(self): pyinsane2.init() - self.devices = pyinsane2.get_devices() + self.devices = get_devices() self.assertTrue(len(self.devices) > 0) def test_get_option(self): @@ -89,7 +95,7 @@ class TestSaneScan(unittest.TestCase): def setUp(self): pyinsane2.init() - devices = pyinsane2.get_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) self.dev = devices[0] diff --git a/tests/tests_saneapi.py b/tests/tests_saneapi.py index 1bbbefcfc54078bbc20d57929cf0968990af1820..d15353821d011dd714cf3ede0579ea1120502179 100644 --- a/tests/tests_saneapi.py +++ b/tests/tests_saneapi.py @@ -5,7 +5,7 @@ if os.name != "nt": from pyinsane2.sane import rawapi -def get_test_devices(): +def get_devices(): '''Return SANE devices, perhaps after creating a test device.''' devices = rawapi.sane_get_devices() if len(devices) == 0: @@ -36,7 +36,7 @@ class TestSaneGetDevices(unittest.TestCase): @unittest.skipIf(os.name == "nt", "sane only") def test_get_devices(self): - devices = get_test_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) def tearDown(self): @@ -46,7 +46,7 @@ class TestSaneGetDevices(unittest.TestCase): class TestSaneOpen(unittest.TestCase): def setUp(self): rawapi.sane_init() - devices = get_test_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) self.dev_name = devices[0].name @@ -66,7 +66,7 @@ class TestSaneOpen(unittest.TestCase): class TestSaneGetOptionDescriptor(unittest.TestCase): def setUp(self): rawapi.sane_init() - devices = get_test_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) dev_name = devices[0].name self.dev_handle = rawapi.sane_open(dev_name) @@ -104,7 +104,7 @@ class TestSaneGetOptionDescriptor(unittest.TestCase): class TestSaneControlOption(unittest.TestCase): def setUp(self): rawapi.sane_init() - devices = get_test_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) dev_name = devices[0].name self.dev_handle = rawapi.sane_open(dev_name) @@ -146,7 +146,7 @@ class TestSaneControlOption(unittest.TestCase): class TestSaneScan(unittest.TestCase): def setUp(self): rawapi.sane_init() - devices = get_test_devices() + devices = get_devices() self.assertTrue(len(devices) > 0) dev_name = devices[0].name self.dev_handle = rawapi.sane_open(dev_name)