From 8bb7698f1fd89935c7feda7e0930808394b34dc8 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 27 Dec 2017 02:40:15 -0500
Subject: [PATCH 2/3] Fix abstract testing with test device.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
tests/tests_abstract.py | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/tests/tests_abstract.py b/tests/tests_abstract.py
index 7dc4bdb..552b052 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]
--
2.13.6