Ejemplo n.º 1
0
    def test_found_non_windows(self):
        "zbar loaded ok on non-Windows platform"
        self.platform.system.return_value = 'Not windows'

        res = zbar_library.load()

        self.platform.system.assert_called_once_with()
        self.find_library.assert_called_once_with('zbar')
        self.cdll.LoadLibrary.assert_called_once_with(
            self.find_library.return_value
        )

        self.assertEqual((self.cdll.LoadLibrary.return_value, []), res)
        self.assertEqual(0, self.windows_fnames.call_count)
Ejemplo n.º 2
0
    def test_found_windows(self):
        "zbar found on Windows"
        self.platform.system.return_value = 'Windows'

        res = zbar_library.load()

        self.platform.system.assert_called_once_with()
        self.cdll.LoadLibrary.assert_has_calls([
            call('dependency fname'),
            call('dll fname'),
        ])
        self.assertEqual(
            (
                self.cdll.LoadLibrary.return_value,
                [self.cdll.LoadLibrary.return_value]
            ),
            res
        )
Ejemplo n.º 3
0
    def test_found_second_attempt_windows(self):
        "zbar found on the second attempt on Windows"
        self.platform.system.return_value = 'Windows'
        self.cdll.LoadLibrary.side_effect = [
            OSError,                # First call does not load dependent DLL
            'loaded dependency',    # Second call loads dependent DLL
            'loaded zbar',          # Third call loads dependent DLL
        ]

        res = zbar_library.load()

        self.platform.system.assert_called_once_with()
        self.cdll.LoadLibrary.assert_has_calls([
            call('dependency fname'),
            call(str(Path(zbar_library.__file__).parent.joinpath(
                'dependency fname'
            ))),
            call(str(Path(zbar_library.__file__).parent.joinpath(
                'dll fname'
            ))),
        ])

        self.assertEqual(('loaded zbar', ['loaded dependency']), res)