Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip some tests if unpackaged files not present, make some files path-y-er #1825

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

mattwthompson
Copy link
Member

The tests currently make some unsafe assumptions about files present relative to the Python package. For example, this does not necessarily point to the root of the repository, since many files are not packaged:

ROOT_DIR_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "..", ".."
)

From this, peeking at the README.md file (or looking for an examples/ directory) can introduce some surprises:

In [1]: import pathlib, os

In [2]: from openff.toolkit._tests.test_links import __file__

In [3]: os.system(f"head {pathlib.Path(__file__).parents[3] / 'README.md'}")
# autoflake

[![Build Status](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml)

## Introduction

_autoflake_ removes unused imports and unused variables from Python code. It
makes use of [pyflakes](https://pypi.org/pypi/pyflakes) to do this.

By default, autoflake only removes unused imports for modules that are part of
Out[3]: 0

This change simply has fixtures return empty lists when it looks like tests are being collected from a packaged path (as distinct from a local path, where the full contents of the repository may be present).

@mattwthompson mattwthompson mentioned this pull request Feb 15, 2024
5 tasks
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Merging #1825 (6c31044) into main (3c56d29) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

@mattwthompson mattwthompson force-pushed the skip-tests-if-files-not-packaged branch from 533dde6 to a1b831f Compare February 15, 2024 17:53
@mattwthompson mattwthompson marked this pull request as ready for review February 15, 2024 18:02
@mattwthompson mattwthompson requested a review from j-wags February 15, 2024 18:02
Copy link
Member

@j-wags j-wags left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mattwthompson!

}
# Examples that require RDKit
rdkit_examples = {
examples_dir_path / "conformer_energies/conformer_energies.py"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, trippy. I didn't realize that Path objects overrode the / operator. Made my day.

@mattwthompson mattwthompson changed the title Skip some tests if unpackaged files not present Skip some tests if unpackaged files not present, make some files path-y-er Feb 22, 2024
Move stuff around to demonstrate skipping

Revert

Make diff simpler
@mattwthompson mattwthompson force-pushed the skip-tests-if-files-not-packaged branch from 3cdd41a to 6c31044 Compare February 22, 2024 21:02
@mattwthompson mattwthompson merged commit db5ddfb into main Feb 22, 2024
18 checks passed
@mattwthompson mattwthompson deleted the skip-tests-if-files-not-packaged branch February 22, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants