code: def test_select_specified_percentage_of_samples_per_category():
      labels, num_samples_per_class, _, _, _ = _test_data()
      random_seed = 0
      percentages = [0, 20, 40, 60, 80, 100, 120]
      for percentage in percentages:
          if 0 < percentage <= 100:
              selected_sample_indices = (
                  common.select_samples_by_category(
                      sample_category_labels=labels,
                      random_seed=random_seed,
                      percentage_of_samples_per_category=percentage,
                  )
              )
              num_expected_samples = np.sum(
                  [
                      int(val * percentage / 100)
                      for val in num_samples_per_class.values()
                  ]
              )
              assert (
                  len(selected_sample_indices) == num_expected_samples
              )
  
              for label, num_samples in num_samples_per_class.items():
                  num_selected_samples_in_class = len(
                      [
                          ind
                          for ind in selected_sample_indices
                          if labels[ind] == label
                      ]
                  )
                  assert num_selected_samples_in_class == int(
                      num_samples * percentage / 100
                  )
          else:
              with pytest.raises(ValueError):
                  common.select_samples_by_category(
                      sample_category_labels=labels,
                      random_seed=random_seed,
                      percentage_of_samples_per_category=percentage,
                  )
  
file_path: ml-cvnets/tests/data/datasets/utils/test_common.py
imports: import numpy
  import pytest
  from data.datasets.utils import common
label_desc: Use image node_id 3 for calling a global function with example usage: test_select_specified_percentage_of_samples_per_category() without return types