Skip to content

Commit f1be9a9

Browse files
committed
PR-7456 unit tests for ctorm
1 parent f591074 commit f1be9a9

5 files changed

Lines changed: 79 additions & 12 deletions

File tree

.github/workflows/test.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: ['3.9', '3.10', '3.11', '3.12']
11+
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
1212
fail-fast: false
1313

1414
steps:
15-
- uses: actions/checkout@v4
16-
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v5
18-
with:
19-
python-version: ${{ matrix.python-version }}
20-
- name: Install dependencies
21-
run: |
22-
python -m pip install --upgrade pip
23-
python -m pip install poetry "tox<4.0.0" tox-poetry tox-gh-actions
24-
- run: make tests
15+
- uses: actions/checkout@v4
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install poetry "tox<4.0.0" tox-poetry tox-gh-actions
24+
- name: Run tests
25+
run: |
26+
make tests
27+
if [ "${{ matrix.python-version }}" = "3.12" ]; then
28+
# ctorm supports py312 only.
29+
make ctorm-test
30+
fi

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ TOX_INIS := $(PACKAGES:%=%/tox.ini)
1313
.PHONY: tests
1414
tests: $(TOX_INIS)
1515
ss=0; $(foreach package,$(PACKAGES),cd $(package) && tox || ss=1;cd ..;) exit $$ss
16+
17+
.PHONY: ctorm-test
18+
ctorm-test:
19+
cd ctorm && tox -c pyproject.toml

ctorm/pyproject.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ authors = [
99
requires-python = ">=3.12"
1010
dependencies = [
1111
"boto3>=1.43.26",
12+
"mypy-boto3-s3>=1.43.14",
1213
]
1314

1415
[dependency-groups]
1516
dev = [
1617
"black>=26.5.1",
1718
"boto3-stubs>=1.43.27",
18-
"mypy-boto3-s3>=1.43.14",
1919
"pytest>=8.0.0",
2020
"ruff>=0.15.13",
2121
]
@@ -29,3 +29,17 @@ build-backend = "uv_build"
2929

3030
[tool.uv.build-backend]
3131
module-root = ""
32+
33+
34+
[tool.tox]
35+
legacy_tox_ini = """
36+
[tox]
37+
envlist = py312
38+
[testenv]
39+
deps =
40+
mypy-boto3-s3
41+
pytest
42+
pytest-mock
43+
commands =
44+
pytest
45+
"""

ctorm/tests/__init__.py

Whitespace-only changes.

ctorm/tests/test_config.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from unittest.mock import mock_open, patch
2+
3+
from ctorm.config import ConfigError, CtormBucket, CtormConfig
4+
5+
6+
def test_ctorm_bucket_initialization():
7+
bucket = CtormBucket(bucketname="test_bucket", share=50, ummg_prefix="test_prefix/")
8+
9+
assert bucket.bucketname == "test_bucket"
10+
assert bucket.share == 50
11+
assert bucket.ummg_prefix == "test_prefix/"
12+
assert bucket.next_cont_token is None
13+
14+
15+
def test_ctorm_config_from_file_success():
16+
mock_data = """
17+
[ctorm]
18+
source_buckets = [{"bucketname": "test_bucket", "share": 50}]
19+
granules_sqs_queue_url = "https://sqs.queue.url/"
20+
"""
21+
with patch("builtins.open", mock_open(read_data=mock_data)), patch("tomllib.load") as mock_toml:
22+
mock_toml.return_value = {
23+
"ctorm": {
24+
"source_buckets": [{"bucketname": "test_bucket", "share": 50}],
25+
"granules_sqs_queue_url": "https://sqs.queue.url/",
26+
}
27+
}
28+
config = CtormConfig.from_file("test.cfg")
29+
30+
assert config.granules_sqs_queue_url == "https://sqs.queue.url/"
31+
assert len(config.source_buckets) == 1
32+
assert isinstance(config.source_buckets[0], CtormBucket)
33+
assert config.source_buckets[0].bucketname == "test_bucket"
34+
35+
36+
def test_ctorm_config_from_file_missing_section():
37+
mock_data = "{}"
38+
with patch("builtins.open", mock_open(read_data=mock_data)), patch("tomllib.load") as mock_toml:
39+
mock_toml.return_value = {}
40+
try:
41+
CtormConfig.from_file("test.cfg")
42+
except ConfigError as e:
43+
assert str(e) == "No 'ctorm' section in config file"

0 commit comments

Comments
 (0)