def get_cffi_modules(): cffi_modules = [ 'libqtile/pango_ffi_build.py:pango_ffi', 'libqtile/backend/x11/xcursors_ffi_build.py:xcursors_ffi', ] try: from cffi.error import PkgConfigError from cffi.pkgconfig import call except ImportError: # technically all ffi defined above wont be built print('CFFI package is missing') else: try: call('libpulse', '--libs') except PkgConfigError: print('Failed to find pulseaudio headers. ' 'PulseVolume widget will be unavailable') else: cffi_modules.append( 'libqtile/widget/pulseaudio_ffi.py:pulseaudio_ffi') try: import wlroots.ffi_build cffi_modules.append( 'libqtile/backend/wayland/libinput_ffi_build.py:libinput_ffi', ) except ImportError: print("Failed to find pywlroots. " "Wayland backend libinput configuration will be unavailable.") pass return cffi_modules
def test_call(): saved = pkgconfig.subprocess try: pkgconfig.subprocess = mock_subprocess mock_subprocess.RESULT = None e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value) == "cannot run pkg-config: oops can't run" mock_subprocess.RESULT = b"", "Foo error!\n", 1 e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value) == "Foo error!" mock_subprocess.RESULT = b"abc\\def\n", "", 0 e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags") assert str(e.value).startswith("pkg-config --cflags libfoo returned an " "unsupported backslash-escaped output:") mock_subprocess.RESULT = b"abc def\n", "", 0 result = pkgconfig.call("libfoo", "--cflags") assert result == "abc def\n" mock_subprocess.RESULT = b"abc def\n", "", 0 result = pkgconfig.call("libfoo", "--cflags") assert result == "abc def\n" if sys.version_info >= (3,): mock_subprocess.RESULT = b"\xff\n", "", 0 e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", "--cflags", encoding="utf-8") assert str(e.value) == ( "pkg-config --cflags libfoo returned bytes that cannot be " "decoded with encoding 'utf-8':\nb'\\xff\\n'") finally: pkgconfig.subprocess = saved