| Conditions | 1 |
| Total Lines | 55 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # coding=utf-8 |
||
| 52 | @pytest.mark.parametrize( |
||
| 53 | "config_paths", |
||
| 54 | [ |
||
| 55 | ["config/unpaired_labeled_ddf.yaml"], |
||
| 56 | ["config/unpaired_labeled_ddf.yaml", "config/test/affine.yaml"], |
||
| 57 | ], |
||
| 58 | ) |
||
| 59 | def test_train_and_predict_main(config_paths): |
||
| 60 | """ |
||
| 61 | Test main in train and predict by checking it can run. |
||
| 62 | |||
| 63 | :param config_paths: list of file paths for configuration. |
||
| 64 | """ |
||
| 65 | train_main( |
||
| 66 | args=[ |
||
| 67 | "--gpu", |
||
| 68 | "", |
||
| 69 | "--exp_name", |
||
| 70 | "test_train", |
||
| 71 | "--config_path", |
||
| 72 | ] |
||
| 73 | + config_paths |
||
| 74 | ) |
||
| 75 | |||
| 76 | # check output folders |
||
| 77 | assert os.path.isdir("logs/test_train/save") |
||
| 78 | assert os.path.isdir("logs/test_train/train") |
||
| 79 | assert os.path.isdir("logs/test_train/validation") |
||
| 80 | assert os.path.isfile("logs/test_train/config.yaml") |
||
| 81 | |||
| 82 | predict_main( |
||
| 83 | args=[ |
||
| 84 | "--gpu", |
||
| 85 | "", |
||
| 86 | "--ckpt_path", |
||
| 87 | "logs/test_train/save/ckpt-2", |
||
| 88 | "--split", |
||
| 89 | "test", |
||
| 90 | "--exp_name", |
||
| 91 | "test_predict", |
||
| 92 | "--save_nifti", |
||
| 93 | "--save_png", |
||
| 94 | ] |
||
| 95 | ) |
||
| 96 | |||
| 97 | # check output folders |
||
| 98 | assert os.path.isdir("logs/test_predict/test/pair_0_1/label_0") |
||
| 99 | assert os.path.isdir("logs/test_predict/test/pair_0_1/label_1") |
||
| 100 | assert os.path.isdir("logs/test_predict/test/pair_0_1/label_2") |
||
| 101 | assert os.path.isfile("logs/test_predict/test/metrics.csv") |
||
| 102 | assert os.path.isfile("logs/test_predict/test/metrics_stats_per_label.csv") |
||
| 103 | assert os.path.isfile("logs/test_predict/test/metrics_stats_overall.csv") |
||
| 104 | |||
| 105 | shutil.rmtree("logs/test_train") |
||
| 106 | shutil.rmtree("logs/test_predict") |
||
| 107 |