diff --git a/tests/test_ldd.py b/tests/test_ldd.py index 07de2c3..e04859b 100644 --- a/tests/test_ldd.py +++ b/tests/test_ldd.py @@ -3,7 +3,6 @@ # pylint: disable=missing-docstring,too-many-public-methods import pathlib import tempfile -import textwrap import unittest from typing import Any, List, Optional @@ -145,11 +144,11 @@ def test_parse_wrong_line(self): def test_parse_static(self) -> None: """Test parsing of the output when we ldd a static library.""" # pylint: disable=protected-access - deps = lddwrap._cmd_output_parser( - textwrap.dedent('''\ - my_static_lib.so: - statically linked - ''')) + deps = lddwrap._cmd_output_parser("\n".join([ + "my_static_lib.so:", + " statically linked", + "", + ])) self.assertListEqual([], deps) @@ -159,10 +158,12 @@ def test_pwd(self): """Test parsing the captured output of ``ldd`` on ``/bin/pwd``.""" with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffe0953f000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)\n'''), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffe0953f000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000)", # pylint: disable=C0301 # pylint: disable=C0301 + "\t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)", + "", + ]), out_unused=''): deps = lddwrap.list_dependencies( path=pathlib.Path('/bin/pwd'), unused=False) @@ -201,15 +202,16 @@ def test_bin_dir(self): # pylint: disable=line-too-long with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffd66ce2000) - \tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000) - \tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000) - \tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000) - \tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)\n''' - ), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffd66ce2000)", + "\tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000)", + "\tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000)", + "\tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000)", + "\t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000)", + "\tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)", + "", + ]), out_unused=''): # pylint: enable=line-too-long deps = lddwrap.list_dependencies( @@ -271,15 +273,16 @@ def test_bin_dir(self): def test_bin_dir_with_empty_unused(self): # pylint: disable=line-too-long with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffd66ce2000) - \tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000) - \tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000) - \tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000) - \tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)\n''' - ), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffd66ce2000)", + "\tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000)", + "\tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000)", + "\tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000)", + "\t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000)", + "\tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)", + "", + ]), out_unused=''): # pylint: enable=line-too-long deps = lddwrap.list_dependencies( @@ -292,13 +295,17 @@ def test_with_fantasy_unused(self): """Test against a fantasy executable with fantasy unused.""" # pylint: disable=line-too-long with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffd66ce2000) - \tlibm.so.6 => /lib64/libm.so.6 (0x00007f72b7e76000)\n''' - ), - out_unused=textwrap.dedent('''\ - Unused direct dependencies: - \t/lib64/libm.so.6\n''')): + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffd66ce2000)", + "\tlibm.so.6 => /lib64/libm.so.6 (0x00007f72b7e76000)", + "", + ]), + out_unused="\n".join([ + "Unused direct dependencies:", + "\t/lib64/libm.so.6", + "", + ]), + ): # pylint: enable=line-too-long deps = lddwrap.list_dependencies( path=pathlib.Path("/bin/dir"), unused=True) @@ -328,9 +335,11 @@ def test_with_static_library(self) -> None: lib_pth.write_text("totally static!") with tests.MockLdd( - out=textwrap.dedent('''\ - my_static_lib.so: - \tstatically linked\n'''), + out="\n".join([ + "my_static_lib.so:", + "\tstatically linked", + "", + ]), out_unused=''): # pylint: enable=line-too-long deps = lddwrap.list_dependencies(path=lib_pth, unused=True) @@ -344,15 +353,16 @@ class TestSorting(unittest.TestCase): def test_sorting_by_all_attributes(self) -> None: # pylint: disable=line-too-long with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffd66ce2000) - \tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000) - \tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000) - \tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000) - \tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)\n''' - ), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffd66ce2000)", + "\tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f72b88fc000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72b850b000)", + "\tlibpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f72b8299000)", + "\tlibdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72b8095000)", + "\t/lib64/ld-linux-x86-64.so.2 (0x00007f72b8d46000)", + "\tlibpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f72b7e76000)", + "", + ]), out_unused=''): # pylint: enable=line-too-long diff --git a/tests/test_main.py b/tests/test_main.py index 84ab219..6d0dce4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -120,10 +120,12 @@ def test_main(self): sys_argv=["some-executable.py", "/bin/pwd"]) with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffe0953f000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)\n'''), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffe0953f000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000)", # pylint: disable=C0301 + "\t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)", + "", + ]), out_unused=''): retcode = lddwrap.main._main(args=args, stream=stream) @@ -149,10 +151,12 @@ def test_sorted_without_specific_attribute(self): sys_argv=["some-executable.py", "/bin/pwd", "--sorted"]) with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffe0953f000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)\n'''), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffe0953f000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000)", # pylint: disable=C0301 + "\t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)", + "", + ]), out_unused=''): retcode = lddwrap.main._main(args=args, stream=stream) @@ -178,10 +182,11 @@ def test_sorted_with_specific_attribute(self): sys_argv=["some-executable.py", "/bin/pwd", "--sorted", "path"]) with tests.MockLdd( - out=textwrap.dedent('''\ - \tlinux-vdso.so.1 (0x00007ffe0953f000) - \tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000) - \t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)\n'''), + out="\n".join([ + "\tlinux-vdso.so.1 (0x00007ffe0953f000)", + "\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd548353000)", # pylint: disable=C0301 + "\t/lib64/ld-linux-x86-64.so.2 (0x00007fd54894d000)", + ]), out_unused=''): retcode = lddwrap.main._main(args=args, stream=stream)