|
| 1 | +import pytest |
| 2 | + |
| 3 | +from .queuespec import QueueSpec |
| 4 | + |
| 5 | + |
| 6 | +def test_single_queue_parsing(): |
| 7 | + spec = QueueSpec.parse("production=10") |
| 8 | + assert spec.queues == ["production"] |
| 9 | + assert spec.concurrency == 10 |
| 10 | + |
| 11 | + |
| 12 | +def test_multi_queue_parsing(): |
| 13 | + spec = QueueSpec.parse("high,medium,low=5") |
| 14 | + assert spec.queues == ["high", "medium", "low"] |
| 15 | + assert spec.concurrency == 5 |
| 16 | + |
| 17 | + |
| 18 | +def test_whitespace_handling(): |
| 19 | + spec = QueueSpec.parse(" api , background = 8 ") |
| 20 | + assert spec.queues == ["api", "background"] |
| 21 | + assert spec.concurrency == 8 |
| 22 | + |
| 23 | + |
| 24 | +def test_empty_spec_error(): |
| 25 | + with pytest.raises(ValueError, match="Queue spec cannot be empty"): |
| 26 | + QueueSpec.parse("") |
| 27 | + |
| 28 | + |
| 29 | +def test_missing_equals_error(): |
| 30 | + with pytest.raises(ValueError, match="Invalid queue spec"): |
| 31 | + QueueSpec.parse("production") |
| 32 | + |
| 33 | + |
| 34 | +def test_empty_concurrency_error(): |
| 35 | + with pytest.raises(ValueError, match="Concurrency must be a positive integer"): |
| 36 | + QueueSpec.parse("queue=") |
| 37 | + |
| 38 | + |
| 39 | +def test_invalid_concurrency_error(): |
| 40 | + with pytest.raises(ValueError, match="Concurrency must be a positive integer"): |
| 41 | + QueueSpec.parse("queue=abc") |
| 42 | + |
| 43 | + |
| 44 | +def test_zero_concurrency_error(): |
| 45 | + with pytest.raises(ValueError, match="Concurrency must be a positive integer"): |
| 46 | + QueueSpec.parse("queue=0") |
| 47 | + |
| 48 | + |
| 49 | +def test_negative_concurrency_error(): |
| 50 | + with pytest.raises(ValueError, match="Concurrency must be a positive integer"): |
| 51 | + QueueSpec.parse("queue=-5") |
| 52 | + |
| 53 | + |
| 54 | +def test_empty_queue_names_error(): |
| 55 | + with pytest.raises(ValueError, match="No valid queue names found"): |
| 56 | + QueueSpec.parse("=10") |
| 57 | + |
| 58 | + |
| 59 | +def test_comma_only_error(): |
| 60 | + with pytest.raises(ValueError, match="Invalid queue spec"): |
| 61 | + QueueSpec.parse(",") |
| 62 | + |
| 63 | + |
| 64 | +def test_empty_queue_names_in_list(): |
| 65 | + spec = QueueSpec.parse("queue1,,queue2=5") |
| 66 | + assert spec.queues == ["queue1", "queue2"] |
| 67 | + assert spec.concurrency == 5 |
0 commit comments