Skip to content

Commit

Permalink
test(compat): only test platform-specific compat results to each plat…
Browse files Browse the repository at this point in the history
…form.

Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Mar 4, 2023
1 parent a98279f commit 0ab5735
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# -*- coding: utf-8 -*-

"""Compat module unit tests."""

import os
import sys
from pathlib import Path

import pytest
from pytest_mock import MockFixture
import sys
import os

from pydngconverter import compat

platform_params = ["Linux", "Windows", "Darwin"]


@pytest.fixture(params=platform_params)
@pytest.fixture(
params=[
pytest.param(
p, marks=pytest.mark.skipif(compat.platform.system() != p, reason=f"{p} only.")
)
for p in platform_params
]
)
def mock_platform(request: pytest.FixtureRequest, mocker: MockFixture):
mocker.patch.object(compat.platform, "system", return_value=request.param)
return request.param


Expand Down Expand Up @@ -61,18 +67,15 @@ async def test_get_compat_path(mocker: MockFixture, platform_paths):
def test_resolve_executable(mocker: MockFixture, platform_apps):
platform, expect_path = platform_apps
mocker.patch("pydngconverter.compat.Path.exists", return_value=True)
if platform == "Windows" and not sys.platform.startswith("win"):
pytest.skip("skipping windows-only test")
ret_path = compat.resolve_executable(["ExampleApp"])
assert str(ret_path) == str(expect_path)


def test_resolve_executable_override(mocker):
mocker.patch("pydngconverter.compat.Path.exists", return_value=True)
os.environ["PYDNG_TEST_KEY"] = "/some/fake/path_exec"
assert (
str(compat.resolve_executable(["path_exec"], env_override="PYDNG_TEST_KEY"))
== "/some/fake/path_exec"
os.environ["PYDNG_TEST_KEY"] = str(Path("/some/fake/path_exec"))
assert Path(compat.resolve_executable(["path_exec"], env_override="PYDNG_TEST_KEY")) == Path(
"/some/fake/path_exec"
)


Expand Down

0 comments on commit 0ab5735

Please sign in to comment.