diff --git a/audbcards/core/datacard.py b/audbcards/core/datacard.py index 5a2f5e1..5faf0ec 100644 --- a/audbcards/core/datacard.py +++ b/audbcards/core/datacard.py @@ -140,6 +140,8 @@ def file_duration_distribution(self) -> str: under ``/-file-durations.png`` and displayed between the minimum and maximum values. + If all duration values are the same, + no distribution plot is created. """ min_ = 0 @@ -149,6 +151,12 @@ def file_duration_distribution(self) -> str: if len(durations) > 0: min_ = np.min(durations) max_ = np.max(durations) + + # Skip creating a distribution plot, + # if all durations are the same + if min_ == max_: + return f"each file is {max_:.1f} {unit}" + distribution_str = f"{min_:.1f} {unit} .. {max_:.1f} {unit}" # Save distribution plot diff --git a/tests/test_data/rendered_templates/bare_db.rst b/tests/test_data/rendered_templates/bare_db.rst index 223d5db..1e888b4 100644 --- a/tests/test_data/rendered_templates/bare_db.rst +++ b/tests/test_data/rendered_templates/bare_db.rst @@ -14,7 +14,7 @@ channel sampling rate bit depth duration 0 days 00:00:00 -files 0, duration distribution: 0.0 s .. 0.0 s +files 0, duration distribution: each file is 0.0 s repository `data-local <.../data-local/bare_db>`__ published 2023-04-05 by author ============= ====================== diff --git a/tests/test_data/rendered_templates/minimal_db.rst b/tests/test_data/rendered_templates/minimal_db.rst index e5ff95b..5e9b055 100644 --- a/tests/test_data/rendered_templates/minimal_db.rst +++ b/tests/test_data/rendered_templates/minimal_db.rst @@ -16,7 +16,7 @@ channel 1 sampling rate 8000 bit depth 16 duration 0 days 00:00:00.100000 -files 1, duration distribution: 0.1 s .. 0.1 s +files 1, duration distribution: each file is 0.1 s repository `data-local <.../data-local/minimal_db>`__ published 2023-04-05 by author ============= ====================== diff --git a/tests/test_datacard.py b/tests/test_datacard.py index 4a6e9ac..098626b 100644 --- a/tests/test_datacard.py +++ b/tests/test_datacard.py @@ -116,17 +116,21 @@ def test_datacard_file_duration_distribution( f"{db.name}-file-durations.png", ) assert not os.path.exists(image_file) - expected_distribution_str = f"{expected_min:.1f} s .. {expected_max:.1f} s" + if expected_min == expected_max: + expected_distribution_str = f"each file is {expected_max:.1f} s" + else: + expected_distribution_str = f"{expected_min:.1f} s .. {expected_max:.1f} s" assert expected_distribution_str == distribution_str # Set sphinx src and build dir and execute again datacard.sphinx_build_dir = build_dir datacard.sphinx_src_dir = src_dir distribution_str = datacard.file_duration_distribution - assert os.path.exists(image_file) - expected_distribution_str = ( - f"{expected_min:.1f} s |{db.name}-file-durations| {expected_max:.1f} s" - ) + if expected_min != expected_max: + assert os.path.exists(image_file) + expected_distribution_str = ( + f"{expected_min:.1f} s |{db.name}-file-durations| {expected_max:.1f} s" + ) assert expected_distribution_str == distribution_str