p2irc / deepplantphenomics

Deep learning for plant phenotyping.
GNU General Public License v2.0
135 stars 46 forks source link

Test run bugfix and refactoring #23

Closed donovanlavoie closed 5 years ago

donovanlavoie commented 5 years ago

This handles a bug in the testing process where running our tests with pytest from the root of the repository would attempt to run the example models in the examples folder.

The test functions and data were all moved into a tests folder under the source root while the offending example scripts were renamed to stay out of pytest's radar. Alongside this fix, a test target for make was also added and a .ini file was added in the root telling pytest to ignore the deprecation and future warnings coming from dependencies (tensorflow in particular).

Pytest's test detection was checked by running it with the -v option, which conveniently makse it print every test name it runs. The output is below, showing that it now only runs the actual tests.

============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 -- /home/donovan/py_envs/fresh_env/bin/python
cachedir: .pytest_cache
rootdir: /home/donovan/test_repos/deepplantphenomics, inifile: pytest.ini
collected 39 items                                                             

deepplantphenomics/tests/test_dpp.py::test_set_number_of_threads PASSED  [  2%]
deepplantphenomics/tests/test_dpp.py::test_set_processed_images_dir PASSED [  5%]
deepplantphenomics/tests/test_dpp.py::test_set_batch_size PASSED         [  7%]
deepplantphenomics/tests/test_dpp.py::test_set_num_regression_outputs PASSED [ 10%]
deepplantphenomics/tests/test_dpp.py::test_set_maximum_training_epochs PASSED [ 12%]
deepplantphenomics/tests/test_dpp.py::test_set_learning_rate PASSED      [ 15%]
deepplantphenomics/tests/test_dpp.py::test_set_crop_or_pad_images PASSED [ 17%]
deepplantphenomics/tests/test_dpp.py::test_set_resize_images PASSED      [ 20%]
deepplantphenomics/tests/test_dpp.py::test_set_augmentation_flip_horizontal PASSED [ 23%]
deepplantphenomics/tests/test_dpp.py::test_set_augmentation_flip_vertical PASSED [ 25%]
deepplantphenomics/tests/test_dpp.py::test_set_augmentation_crop PASSED  [ 28%]
deepplantphenomics/tests/test_dpp.py::test_set_augmentation_brightness_and_contrast PASSED [ 30%]
deepplantphenomics/tests/test_dpp.py::test_set_regularization_coefficient PASSED [ 33%]
deepplantphenomics/tests/test_dpp.py::test_set_learning_rate_decay PASSED [ 35%]
deepplantphenomics/tests/test_dpp.py::test_set_optimizer PASSED          [ 38%]
deepplantphenomics/tests/test_dpp.py::test_set_weight_initializer PASSED [ 41%]
deepplantphenomics/tests/test_dpp.py::test_set_image_dimensions PASSED   [ 43%]
deepplantphenomics/tests/test_dpp.py::test_set_original_image_dimensions PASSED [ 46%]
deepplantphenomics/tests/test_dpp.py::test_set_patch_size PASSED         [ 48%]
deepplantphenomics/tests/test_dpp.py::test_add_preprocessor PASSED       [ 51%]
deepplantphenomics/tests/test_dpp.py::test_set_problem_type PASSED       [ 53%]
deepplantphenomics/tests/test_dpp.py::test_set_yolo_parameters PASSED    [ 56%]
deepplantphenomics/tests/test_dpp.py::test_add_input_layer PASSED        [ 58%]
deepplantphenomics/tests/test_dpp.py::test_add_convolutional_layer PASSED [ 61%]
deepplantphenomics/tests/test_dpp.py::test_add_pooling_layer PASSED      [ 64%]
deepplantphenomics/tests/test_dpp.py::test_pooling_layer_output_size[2-2-3] PASSED [ 66%]
deepplantphenomics/tests/test_dpp.py::test_pooling_layer_output_size[3-3-2] PASSED [ 69%]
deepplantphenomics/tests/test_dpp.py::test_pooling_layer_output_size[2-1-5] PASSED [ 71%]
deepplantphenomics/tests/test_dpp.py::test_add_normalization_layer PASSED [ 74%]
deepplantphenomics/tests/test_dpp.py::test_add_dropout_layer PASSED      [ 76%]
deepplantphenomics/tests/test_dpp.py::test_add_batch_norm_layer PASSED   [ 79%]
deepplantphenomics/tests/test_dpp.py::test_add_fully_connected_layer PASSED [ 82%]
deepplantphenomics/tests/test_dpp.py::test_add_output_layer PASSED       [ 84%]
deepplantphenomics/tests/test_dpp.py::test_load_dataset_from_directory_with_csv_labels PASSED [ 87%]
deepplantphenomics/tests/test_dpp.py::test_load_ippn_leaf_count_dataset_from_directory PASSED [ 89%]
deepplantphenomics/tests/test_loaders.py::test_read_csv_labels PASSED    [ 92%]
deepplantphenomics/tests/test_loaders.py::test_read_csv_labels_and_ids PASSED [ 94%]
deepplantphenomics/tests/test_loaders.py::test_read_csv_multi_labels_and_ids PASSED [ 97%]
deepplantphenomics/tests/test_loaders.py::test_indices_to_onehot PASSED  [100%]

========================== 39 passed in 1.68 seconds ===========================

There are also a couple of improvements to the testing. Relative imports and file paths were replaced with absolute versions, and one test had some cases added to it. This has been tested to work on a fresh fetch/pull with Python 3.6.