22"""Test lddwrap."""
33# pylint: disable=missing-docstring,too-many-public-methods
44import pathlib
5+ import shutil
56import tempfile
67import unittest
78from typing import Any , List , Optional
1011
1112import tests
1213
14+ # Some distros like NixOS does not have binaries on /bin.
15+ # Instead of hardcoding them, try to get them from PATH
16+ # using shutil.which function.
17+ DIR = shutil .which ("dir" ) or "/bin/dir"
18+ PWD = shutil .which ("pwd" ) or "/bin/pwd"
19+
1320
1421class DependencyDiff :
1522 """Represent a different between two dependencies."""
@@ -200,7 +207,7 @@ def test_pwd(self):
200207 ]),
201208 out_unused = '' ):
202209 deps = lddwrap .list_dependencies (
203- path = pathlib .Path ('/bin/pwd' ), unused = False )
210+ path = pathlib .Path (PWD ), unused = False )
204211
205212 expected_deps = [
206213 lddwrap .Dependency (
@@ -249,7 +256,7 @@ def test_bin_dir(self):
249256 out_unused = '' ):
250257 # pylint: enable=line-too-long
251258 deps = lddwrap .list_dependencies (
252- path = pathlib .Path ('/bin/dir' ), unused = False )
259+ path = pathlib .Path (DIR ), unused = False )
253260
254261 expected_deps = [
255262 lddwrap .Dependency (
@@ -320,7 +327,7 @@ def test_bin_dir_with_empty_unused(self):
320327 out_unused = '' ):
321328 # pylint: enable=line-too-long
322329 deps = lddwrap .list_dependencies (
323- path = pathlib .Path ("/bin/dir" ), unused = True )
330+ path = pathlib .Path (DIR ), unused = True )
324331
325332 unused = [dep for dep in deps if dep .unused ]
326333 self .assertListEqual ([], unused )
@@ -342,7 +349,7 @@ def test_with_fantasy_unused(self):
342349 ):
343350 # pylint: enable=line-too-long
344351 deps = lddwrap .list_dependencies (
345- path = pathlib .Path ("/bin/dir" ), unused = True )
352+ path = pathlib .Path (DIR ), unused = True )
346353
347354 unused = [dep for dep in deps if dep .unused ]
348355
@@ -402,7 +409,7 @@ def test_sorting_by_all_attributes(self) -> None:
402409
403410 for attr in lddwrap .DEPENDENCY_ATTRIBUTES :
404411 deps = lddwrap .list_dependencies (
405- path = pathlib .Path ("/bin/dir" ), unused = True )
412+ path = pathlib .Path (DIR ), unused = True )
406413
407414 # pylint: disable=protected-access
408415 lddwrap ._sort_dependencies_in_place (deps = deps , sort_by = attr )
0 commit comments