Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostofGoes committed May 12, 2022
1 parent 6bda2b1 commit 1a5c774
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
14 changes: 4 additions & 10 deletions getmac/getmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,7 @@ def initialize_method_cache(method_type): # type: (str) -> bool

# Filter methods by the platform we're running on
platform_methods = [
method for method in METHODS
if PLATFORM in method.platforms
method for method in METHODS if PLATFORM in method.platforms
] # type: List[Type[Method]]
if not platform_methods:
# If there isn't a method for the current platform,
Expand All @@ -1150,10 +1149,7 @@ def initialize_method_cache(method_type): # type: (str) -> bool
"Falling back to platform 'other'",
PLATFORM,
)
platform_methods = [
method for method in METHODS
if "other" in method.platforms
]
platform_methods = [method for method in METHODS if "other" in method.platforms]
if DEBUG:
meth_strs = ", ".join(pm.__name__ for pm in platform_methods) # type: str
log.debug("'%s' platform_methods: %s", method_type, meth_strs)
Expand Down Expand Up @@ -1240,9 +1236,7 @@ def _attempt_method_get(
): # type: (Method, str, str) -> Optional[str]
"""Attempt to use methods, and if they fail, fallback to the next method in the cache."""
if not METHOD_CACHE[method_type] and not FALLBACK_CACHE[method_type]:
log.critical(
"No usable methods found for MAC type '%s'", method_type
)
log.critical("No usable methods found for MAC type '%s'", method_type)
return None

result = None
Expand Down Expand Up @@ -1301,7 +1295,7 @@ def get_by_method(method_type, arg=""): # type: (str, str) -> Optional[str]
if not method:
# Initialize the cache if it hasn't been already
initialize_method_cache(method_type)
method = METHOD_CACHE[method_type] # type: Optional[Method]
method = METHOD_CACHE[method_type]
if not method:
log.error(
"Initialization failed for method %s. It may not be supported "
Expand Down
21 changes: 12 additions & 9 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,18 @@ def test_wsl_ifconfig(benchmark, mocker, get_sample):
assert "00:15:5d:83:d9:0a" == benchmark(getmac.IfconfigLinux().get, arg="eth8")


@pytest.mark.parametrize(("expected_mac", "iface_arg"), [
("b4:2e:99:36:1e:33", "eth0"),
("b4:2e:99:35:1e:86", "eth3"),
("00:15:5d:83:d9:0a", "eth8"),
(None, "lo"),
("00:ff:36:20:68:56", "eth15"),
(None, "eth16"),
(None, "eth"),
])
@pytest.mark.parametrize(
("expected_mac", "iface_arg"),
[
("b4:2e:99:36:1e:33", "eth0"),
("b4:2e:99:35:1e:86", "eth3"),
("00:15:5d:83:d9:0a", "eth8"),
(None, "lo"),
("00:ff:36:20:68:56", "eth15"),
(None, "eth16"),
(None, "eth"),
],
)
def test_wsl_ip_link_iface(benchmark, mocker, get_sample, expected_mac, iface_arg):
mocker.patch("getmac.getmac.IpLinkIface._tested_arg", True)
mocker.patch("getmac.getmac.IpLinkIface._iface_arg", False)
Expand Down

0 comments on commit 1a5c774

Please sign in to comment.