Always display test coverage; add tests #240
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
Pull Request overview
pytestis used:data.pytests.onnxthat fail currently.model.onnxis always deleted, even on test failures.Details
pytestimprovementsThis PR introduces
.coveragerc, the recommended configuration file forcoverage. It's fairly standard, except for the exclusion ofif TYPE_CHECKING:branches. As these are never true for users, we don't need to worry about theTruebranch here, so we can safely exclude these branches.Additionally,
setup.cfgis expanded with:This implies
pytestwill now be equivalent topytest --cov=setfit --durations=10 ./tests.--cov=setfitwill print an ascii coverage report at the end of thepytestrun, like so:--durations=10will display the 10 slowest tests, like so:Additionally,
pytest --cov-report=htmlcan be used to create a HTML report in acoverage_report_htmlfolder.New tests
For
data.pyI have introduced several new tests. Although this code likely isn't frequently used by users of SetFit, I wanted to try and understand it better, and what better way to understand code than to try and verify that it works correctly? 😄For the ONNX tests I created a simple Trainer that trains a differentiable head, and then I export that model to ONNX in the same way as the existing test. The reasoning here was that exporting a model was only tested for the sklearn head. I discovered that the tests fail regardless of the
out_featurespassed to the differentiable head.At
out_featuresof 1 there is an issue with training, and at 2 and 3 the following errors pop up, respectively:As you can see, the actual model predictions stay 1-dimensional: simply an array with the number of samples to predict for as the length. However, the ONNX predictions are 2-dimensional of the shape
(num_samples, out_features). Regardless of whether this is an issue on the PyTorch model, the ONNX model should always be equivalent to the PyTorch model.I've skipped these tests with the reason of "ONNX exporting of SetFit model with Torch head not yet supported."
Additionally, I've encompassed the body of the ONNX tests with a
try-finally, where themodel.onnxfile is deleted in the finally clause. That way, the file gets deleted even when the test fails.All in all, this has improved the test coverage from 72% to 77%. It would increase much more when ONNX tests pass, and I've now identified some key code that is never executed, like
SetFitBaseModel,SKLearnWrapper,SetFitPipelineand a majority of logging.py code.