Test batch formatting for Dynamic API.
(test_case, device)
| 219 | |
| 220 | @params(*product(BATCH_TEST_CASES, DEVICES)) |
| 221 | def test_batch_formatting_dynamic(test_case, device): |
| 222 | """Test batch formatting for Dynamic API.""" |
| 223 | layout = test_case["layout"] |
| 224 | num_samples = test_case["num_samples"] |
| 225 | shapes = test_case["shapes"] |
| 226 | should_summarize = test_case["should_summarize"] |
| 227 | arrays = test_case["arrays"] |
| 228 | |
| 229 | if num_samples == 0: |
| 230 | import nvidia.dali.types as types |
| 231 | |
| 232 | b = ndd.batch([], dtype=types.FLOAT, device=device) |
| 233 | else: |
| 234 | b = ndd.batch(arrays, layout=layout, device=device) |
| 235 | |
| 236 | for method_name, method in [("str", str), ("repr", repr)]: |
| 237 | result = method(b) |
| 238 | assert "Batch" in result, f'expected "Batch" in "{result}"' |
| 239 | assert "dtype=" in result, f'expected "dtype=" in "{result}"' |
| 240 | assert f'device="{device}"' in result, f'expected "device=\\"{device}\\"" in "{result}"' |
| 241 | assert ( |
| 242 | f"num_samples={num_samples}" in result |
| 243 | ), f'expected "num_samples={num_samples}" in "{result}"' |
| 244 | if layout: |
| 245 | assert f'layout="{layout}"' in result, f'expected "layout=\\"{layout}\\"" in "{result}"' |
| 246 | |
| 247 | if num_samples > 0: |
| 248 | assert result.count("[") > 1, f'expected multiple "[" in "{result}"' |
| 249 | assert ( |
| 250 | shapes[0] in result and shapes[-1] in result |
| 251 | ), f'expected "{shapes[0]}" and "{shapes[-1]}" in "{result}"' |
| 252 | expected_vals = _format_values(arrays[0]) + _format_values(arrays[-1]) |
| 253 | assert all( |
| 254 | v in result for v in expected_vals |
| 255 | ), f'expected values {expected_vals} in "{result}"' |
| 256 | if should_summarize: |
| 257 | assert "..." in result, f'expected "..." in "{result}"' |
nothing calls this directly
no test coverage detected