diff --git a/tests/test_relabel.py b/tests/test_relabel.py index 6366b83..8eacbe7 100644 --- a/tests/test_relabel.py +++ b/tests/test_relabel.py @@ -11,6 +11,57 @@ logging.disable(logging.CRITICAL) +# ------------------------------------------------------------------------------ +@pytest.mark.usefixtures( + "data_dir", +) +def test_relabel_darknet( + data_dir, +): + """ + Test for the cvdata.relabel.relabel_darknet() function + + :param data_dir: temporary directory into which test files will be loaded + """ + darknet_file_name = "darknet_1.txt" + darknet_file_path = str(data_dir.join(darknet_file_name)) + + # confirm that a relabeling won't occur if the old value is not present + relabel.relabel_darknet(darknet_file_path, 58, 59) + expected_darknet_file_name = "expected_darknet_1.txt" + expected_darknet_file_path = str(data_dir.join(expected_darknet_file_name)) + assert text_files_equal( + darknet_file_path, + expected_darknet_file_path, + ) + + # confirm that relabeling occurred as expected + relabel.relabel_darknet(darknet_file_path, 3, 2) + expected_darknet_file_name = "expected_darknet_2.txt" + expected_darknet_file_path = str(data_dir.join(expected_darknet_file_name)) + assert text_files_equal( + darknet_file_path, + expected_darknet_file_path, + ) + + # confirm that various invalid arguments raise an error + with pytest.raises(TypeError): + relabel.relabel_darknet(darknet_file_path, None, 0) + relabel.relabel_darknet(darknet_file_path, 0, None) + relabel.relabel_darknet(1, 0, 1) + relabel.relabel_darknet(None, 1, 0) + relabel.relabel_darknet("/not/present", 0, 1) + relabel.relabel_darknet(1.0, "strings won't work", 0) + relabel.relabel_darknet(darknet_file_path, 1, "strings won't work") + relabel.relabel_darknet(darknet_file_path, 1.0, 0) + relabel.relabel_darknet(darknet_file_path, 2, 1.0) + relabel.relabel_darknet(darknet_file_path, True, 0) + relabel.relabel_darknet(darknet_file_path, 1, True) + with pytest.raises(ValueError): + relabel.relabel_darknet(darknet_file_path, -5, 1) + relabel.relabel_darknet(darknet_file_path, 1, -4) + + # ------------------------------------------------------------------------------ @pytest.mark.usefixtures( "data_dir", @@ -44,7 +95,7 @@ def test_relabel_kitti( expected_kitti_file_path, ) - # confirm that invalid argument types raise an error + # confirm that various invalid arguments raise an error with pytest.raises(ValueError): relabel.relabel_kitti(None, "don't care", "don't care") relabel.relabel_kitti(kitti_file_path, None, "don't care") @@ -95,7 +146,7 @@ def test_relabel_pascal( etree_after_relabel.getroot(), ) - # confirm that invalid argument types raise an error + # confirm that various invalid arguments raise an error with pytest.raises(ValueError): relabel.relabel_pascal(None, "don't care", "don't care") relabel.relabel_pascal(pascal_file_path, None, "don't care") diff --git a/tests/test_relabel/darknet_1.txt b/tests/test_relabel/darknet_1.txt new file mode 100644 index 0000000..d92d548 --- /dev/null +++ b/tests/test_relabel/darknet_1.txt @@ -0,0 +1 @@ +3 0.4995 0.2012 0.3994 0.0456 diff --git a/tests/test_relabel/expected_darknet_1.txt b/tests/test_relabel/expected_darknet_1.txt new file mode 100644 index 0000000..d92d548 --- /dev/null +++ b/tests/test_relabel/expected_darknet_1.txt @@ -0,0 +1 @@ +3 0.4995 0.2012 0.3994 0.0456 diff --git a/tests/test_relabel/expected_darknet_2.txt b/tests/test_relabel/expected_darknet_2.txt new file mode 100644 index 0000000..4b5c22a --- /dev/null +++ b/tests/test_relabel/expected_darknet_2.txt @@ -0,0 +1 @@ +2 0.4995 0.2012 0.3994 0.0456