Skip to content

Commit

Permalink
Fix tests, and BaseVersion parsing
Browse files Browse the repository at this point in the history
Fail if BaseVersion is built from an "empty" value
  • Loading branch information
benoitryder committed Feb 1, 2025
1 parent 54aff23 commit 28ab215
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 3 additions & 1 deletion cdtb/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class BaseVersion:
"""

def __init__(self, v: Union[str, tuple]):
if not v:
raise ValueError(v)
if isinstance(v, str):
self.s = v
self.t = tuple(int(x) for x in v.split('.'))
elif isinstance(v, tuple):
self.s = '.'.join(str(x) for x in v)
self.s = '.'.join(str(int(x)) for x in v)
self.t = v
else:
raise TypeError(v)
Expand Down
6 changes: 1 addition & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import argparse
import pytest
import cdtb
from cdtb.storage import (
Expand All @@ -9,10 +8,7 @@
PatchElement,
)
import cdtb.__main__ as cdtb_main
from cdtb.__main__ import (
create_parser,
parse_storage_args,
)
from cdtb.__main__ import create_parser


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from tools import *
from tools import count_calls, mock_response
from cdtb.rads import (
RadsVersion,
RadsStorage,
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_project_get_versions(storage, monkeypatch):

@count_calls
def request_get(path):
assert path == f"projects/name/releases/releaselisting"
assert path == "projects/name/releases/releaselisting"
return mock_response(b'0.0.1.7\r\n0.0.1.6\r\n0.0.1.5\r\n')
monkeypatch.setattr(storage, 'request_get', request_get)

Expand Down
11 changes: 6 additions & 5 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pytest
from cdtb.storage import (
BaseVersion,
Expand All @@ -17,10 +16,12 @@ def test_base_version_init_ok(t, s):
assert BaseVersion(s).s == s

@pytest.mark.parametrize("arg, exc", [
(None, TypeError),
(None, ValueError),
("", ValueError),
((), ValueError),
(("1", "2"), TypeError),
(("a", "b"), ValueError),
# Supported but could be refused
#(("1", "2"), ValueError),
])
def test_base_version_init_bad(arg, exc):
with pytest.raises(exc):
Expand Down Expand Up @@ -55,12 +56,12 @@ def test_patch_version_init_ok(arg, t, s):
assert v.s == s

@pytest.mark.parametrize("arg, exc", [
(None, TypeError),
(None, ValueError),
("", ValueError),
("bad", ValueError),
("9", AssertionError),
])
def test_base_version_init_bad(arg, exc):
def test_patch_version_init_bad(arg, exc):
with pytest.raises(exc):
PatchVersion(arg)

0 comments on commit 28ab215

Please sign in to comment.