Skip to content

Commit

Permalink
Checkpoint initial tests for whl2conda build
Browse files Browse the repository at this point in the history
  • Loading branch information
analog-cbarber committed May 5, 2024
1 parent dd0ca59 commit 5b4f696
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test-projects/simple/conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% set project = load_file_data('pyproject.toml')['project'] %}

package:
name: simple
version: {{ project['version'] }}

source:
- path: ..

build:
noarch: python
script: pip install . -vv --no-deps --no-build-isolation

requirements:
build:
- python 3.10
- hatchling

run:
- python {{ project['requires-python'] }}
- black >=23.3
- quaternion
- pytables

test:
requires:
- pytest
imports:
- simple

about:
home: {{ project['urls']['Homepage'] }}
summary: {{ project['description'] }}

extra:
authors:
{% for author in project['authors'] %}
- '{{ author['name'] }} <{{ author['email'] }}>'
{% endfor %}
keywords:
{% for keyword in project['keywords'] %}
- '{{ keyword }}'
{% endfor %}
classifiers:
{% for classifier in project['classifiers'] %}
- '{{ classifier }}'
{% endfor %}
83 changes: 83 additions & 0 deletions test/cli/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2024 Christopher Barber
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Unit tests for whl2conda build subcommand.
"""

from __future__ import annotations

import re
from pathlib import Path

# third party
import pytest

# this project
from whl2conda.cli import main
from whl2conda.cli.build import CondaBuild

this_dir = Path(__file__).parent
root_dir = this_dir.parent.parent
test_projects = root_dir / "test-projects"


class CondaBuildWhitebox(CondaBuild):
def _render_recipe(self):
super()._render_recipe()

def _check_recipe(self) -> str:
new_script = super()._check_recipe()
return new_script

def _build_wheel(self) -> Path:
return super()._build_wheel()

def _build_package(self, wheel: Path) -> Path:
pkg = super()._build_package(wheel)
return pkg

def _test_package(self, pkg: Path) -> None:
pass
# super()._test_package(pkg)

def _install_package(self, pkg: Path) -> None:
pass

def _cleanup(self) -> None:
super()._cleanup()


@pytest.fixture
def build_whitebox(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
):
monkeypatch.setattr("whl2conda.cli.build.CondaBuild", CondaBuildWhitebox)


def test_simple(
build_whitebox,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture,
) -> None:
monkeypatch.chdir(test_projects / "simple")
main(["build", "conda.recipe"])
out, err = capsys.readouterr()
assert not err
assert re.search(
r"Elapsed time: .* seconds",
out,
flags=re.MULTILINE,
)

0 comments on commit 5b4f696

Please sign in to comment.