Skip to content

Commit 83dcdab

Browse files
committed
more docs + make bounds inclusive
1 parent 123d56b commit 83dcdab

File tree

5 files changed

+71
-72
lines changed

5 files changed

+71
-72
lines changed

docs/mkdocs.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ theme:
1111
- navigation.tracking
1212

1313
plugins:
14-
- mkdocstrings
14+
- mkdocstrings:
15+
handlers:
16+
python:
17+
options:
18+
show_signature: true
19+
show_signature_annotations: true
20+
separate_signature: true
21+
1522

1623
markdown_extensions:
1724
- admonition

pum/changelog.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def __repr__(self):
2727
def last_version(
2828
config: PumConfig,
2929
dir: str | Path = ".",
30-
after_version: str | None = None,
31-
before_version: str | None = None,
30+
min_version: str | None = None,
31+
max_version: str | None = None,
3232
) -> str | None:
3333
"""
3434
Return the last version of the changelogs.
@@ -39,16 +39,19 @@ def last_version(
3939
Args:
4040
config (PumConfig): The configuration object.
4141
dir (str | Path): The directory where the changelogs are located.
42-
after_version (str | None): The version to start from.
43-
before_version (str | None): The version to end at.
42+
min_version (str | None): The version to start from (inclusive).
43+
max_version (str | None): The version to end at (inclusive).
44+
45+
Returns:
46+
str | None: The last version of the changelogs. If no changelogs are found, None is returned.
4447
"""
45-
changelogs = list_changelogs(config, dir, after_version, before_version)
48+
changelogs = list_changelogs(config, dir, min_version, max_version)
4649
if not changelogs:
4750
return None
48-
if after_version:
49-
changelogs = [c for c in changelogs if c.version > parse_version(after_version)]
50-
if before_version:
51-
changelogs = [c for c in changelogs if c.version < parse_version(before_version)]
51+
if min_version:
52+
changelogs = [c for c in changelogs if c.version >= parse_version(min_version)]
53+
if max_version:
54+
changelogs = [c for c in changelogs if c.version <= parse_version(max_version)]
5255
if not changelogs:
5356
return None
5457
return changelogs[-1].version
@@ -57,8 +60,8 @@ def last_version(
5760
def list_changelogs(
5861
config: PumConfig,
5962
dir: str | Path = ".",
60-
after_version: str | None = None,
61-
before_version: str | None = None,
63+
min_version: str | None = None,
64+
max_version: str | None = None,
6265
) -> list:
6366
"""
6467
Return a list of changelogs.
@@ -69,8 +72,11 @@ def list_changelogs(
6972
Args:
7073
config (PumConfig): The configuration object.
7174
dir (str | Path): The directory where the changelogs are located.
72-
after_version (str | None): The version to start from.
73-
before_version (str | None): The version to end at.
75+
min_version (str | None): The version to start from (inclusive).
76+
max_version (str | None): The version to end at (inclusive).
77+
78+
Returns:
79+
list: A list of changelogs. Each changelog is represented by a Changelog object.
7480
"""
7581
path = Path(dir)
7682
if not path.is_dir():
@@ -81,10 +87,10 @@ def list_changelogs(
8187

8288
changelogs = [Changelog(path / d) for d in listdir(path) if isdir(join(path, d))]
8389

84-
if after_version:
85-
changelogs = [c for c in changelogs if c.version > parse_version(after_version)]
86-
if before_version:
87-
changelogs = [c for c in changelogs if c.version < parse_version(before_version)]
90+
if min_version:
91+
changelogs = [c for c in changelogs if c.version >= parse_version(min_version)]
92+
if max_version:
93+
changelogs = [c for c in changelogs if c.version <= parse_version(max_version)]
8894

8995
changelogs.sort(key=lambda c: c.version)
9096
return changelogs

pum/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def parameter(self, name) -> MigrationParameterDefintion:
9696
def from_yaml(cls, file_path):
9797
"""
9898
Create a PumConfig instance from a YAML file.
99+
Args:
100+
file_path (str): The path to the YAML file.
101+
Returns:
102+
PumConfig: An instance of the PumConfig class.
103+
Raises:
104+
FileNotFoundError: If the file does not exist.
105+
yaml.YAMLError: If there is an error parsing the YAML file.
99106
"""
100107

101108
with open(file_path) as file:

test/test_changelog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,36 @@ def test_changelog(self):
3333
last_version_result = last_version(
3434
config=cfg,
3535
dir=str(Path("test") / "data" / "multiple_changelogs"),
36-
after_version="1.2.3",
37-
before_version="1.3.0",
36+
min_version="1.2.4",
37+
max_version="1.3.0",
3838
)
39-
self.assertEqual(last_version_result, parse_version("1.2.4"))
39+
self.assertEqual(last_version_result, parse_version("1.3.0"))
4040

4141
last_version_result = last_version(
4242
config=cfg,
4343
dir=str(Path("test") / "data" / "multiple_changelogs"),
44-
before_version="1.3.0",
44+
max_version="1.3.0",
4545
)
46-
self.assertEqual(last_version_result, parse_version("1.2.4"))
46+
self.assertEqual(last_version_result, parse_version("1.3.0"))
4747

4848
last_version_result = last_version(
4949
config=cfg,
5050
dir=str(Path("test") / "data" / "multiple_changelogs"),
51-
before_version="1.2.3",
51+
max_version="1.0.0",
5252
)
5353
self.assertIsNone(last_version_result)
5454

5555
last_version_result = last_version(
5656
config=cfg,
5757
dir=str(Path("test") / "data" / "multiple_changelogs"),
58-
after_version="1.2.3",
58+
min_version="1.2.3",
5959
)
6060
self.assertEqual(last_version_result, parse_version("2.0.0"))
6161

6262
last_version_result = last_version(
6363
config=cfg,
6464
dir=str(Path("test") / "data" / "multiple_changelogs"),
65-
after_version="2.0.0",
65+
min_version="2.1.0",
6666
)
6767
self.assertIsNone(last_version_result)
6868

test/test_upgrader.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ def setUp(self):
4444
self.tmp = self.tmpdir.name
4545

4646
def test_install_single_changelog(self):
47+
test_dir = Path("test") / "data" / "single_changelog"
48+
changelog_file = test_dir / "changelogs" / "1.2.3" / "create_northwind.sql"
4749
cfg = PumConfig()
4850
sm = SchemaMigrations(cfg)
4951
self.assertFalse(sm.exists(self.conn))
5052
upgrader = Upgrader(
5153
pg_service=self.pg_service,
5254
config=cfg,
53-
dir=str(Path("test") / "data" / "single_changelog"),
55+
dir=test_dir,
5456
)
5557
upgrader.install()
5658
self.assertTrue(sm.exists(self.conn))
@@ -59,24 +61,17 @@ def test_install_single_changelog(self):
5961
self.assertEqual(sm.migration_details(self.conn)["version"], "1.2.3")
6062
self.assertEqual(
6163
sm.migration_details(self.conn)["changelog_files"],
62-
[
63-
str(
64-
Path("test")
65-
/ "data"
66-
/ "single_changelog"
67-
/ "changelogs"
68-
/ "1.2.3"
69-
/ "create_northwind.sql"
70-
)
71-
],
64+
[str(changelog_file)],
7265
)
7366

7467
@unittest.skipIf(
7568
os.name == "nt" and os.getenv("CI") == "true",
7669
"Test not supported on Windows CI (postgis not installed)",
7770
)
7871
def test_parameters(self):
79-
cfg = PumConfig.from_yaml(str(Path("test") / "data" / "parameters" / ".pum-config.yaml"))
72+
test_dir = Path("test") / "data" / "parameters"
73+
config_path = test_dir / ".pum-config.yaml"
74+
cfg = PumConfig.from_yaml(str(config_path))
8075
self.assertEqual(
8176
cfg.parameters()["SRID"],
8277
MigrationParameterDefintion(
@@ -91,7 +86,7 @@ def test_parameters(self):
9186
upgrader = Upgrader(
9287
pg_service=self.pg_service,
9388
config=cfg,
94-
dir=str(Path("test") / "data" / "parameters"),
89+
dir=test_dir,
9590
parameters={"SRID": 2056},
9691
)
9792
upgrader.install()
@@ -102,53 +97,57 @@ def test_parameters(self):
10297
self.assertEqual(srid, 2056)
10398

10499
def test_install_custom_directory(self):
105-
cfg = PumConfig.from_yaml(
106-
str(Path("test") / "data" / "custom_directory" / ".pum-config.yaml")
107-
)
100+
test_dir = Path("test") / "data" / "custom_directory"
101+
config_path = test_dir / ".pum-config.yaml"
102+
cfg = PumConfig.from_yaml(str(config_path))
108103
sm = SchemaMigrations(cfg)
109104
self.assertFalse(sm.exists(self.conn))
110105
upgrader = Upgrader(
111106
pg_service=self.pg_service,
112107
config=cfg,
113-
dir=str(Path("test") / "data" / "custom_directory"),
108+
dir=test_dir,
114109
)
115110
upgrader.install()
116111
self.assertTrue(sm.exists(self.conn))
117112

118113
def test_install_custom_migration_table(self):
119-
cfg = PumConfig.from_yaml(
120-
str(Path("test") / "data" / "custom_migration_schema" / ".pum-config.yaml")
121-
)
114+
test_dir = Path("test") / "data" / "custom_migration_schema"
115+
config_path = test_dir / ".pum-config.yaml"
116+
cfg = PumConfig.from_yaml(str(config_path))
122117
sm = SchemaMigrations(cfg)
123118
self.assertFalse(sm.exists(self.conn))
124119
upgrader = Upgrader(
125120
pg_service=self.pg_service,
126121
config=cfg,
127-
dir=str(Path("test") / "data" / "custom_migration_schema"),
122+
dir=test_dir,
128123
)
129124
upgrader.install()
130125
self.assertTrue(sm.exists(self.conn))
131126

132127
def test_install_complex_files_content(self):
128+
complex_dir = Path("test") / "data" / "complex_files_content"
133129
cfg = PumConfig()
134130
sm = SchemaMigrations(cfg)
135131
self.assertFalse(sm.exists(self.conn))
136132
upgrader = Upgrader(
137133
pg_service=self.pg_service,
138134
config=cfg,
139-
dir=str(Path("test") / "data" / "complex_files_content"),
135+
dir=str(complex_dir),
140136
)
141137
upgrader.install()
142138
self.assertTrue(sm.exists(self.conn))
143139

144140
def test_install_multiple_changelogs(self):
141+
test_dir = Path("test") / "data" / "multiple_changelogs"
142+
changelog_file_1 = test_dir / "changelogs" / "2.0.0" / "create_second_table.sql"
143+
changelog_file_2 = test_dir / "changelogs" / "2.0.0" / "create_third_table.sql"
145144
cfg = PumConfig()
146145
sm = SchemaMigrations(cfg)
147146
self.assertFalse(sm.exists(self.conn))
148147
upgrader = Upgrader(
149148
pg_service=self.pg_service,
150149
config=cfg,
151-
dir=str(Path("test") / "data" / "multiple_changelogs"),
150+
dir=test_dir,
152151
)
153152
upgrader.install()
154153
self.assertTrue(sm.exists(self.conn))
@@ -160,35 +159,15 @@ def test_install_multiple_changelogs(self):
160159
self.assertEqual(sm.migration_details(self.conn)["version"], "2.0.0")
161160
self.assertEqual(
162161
sm.migration_details(self.conn)["changelog_files"],
163-
[
164-
str(
165-
Path("test")
166-
/ "data"
167-
/ "multiple_changelogs"
168-
/ "changelogs"
169-
/ "2.0.0"
170-
/ "create_second_table.sql"
171-
),
172-
str(
173-
Path("test")
174-
/ "data"
175-
/ "multiple_changelogs"
176-
/ "changelogs"
177-
/ "2.0.0"
178-
/ "create_third_table.sql"
179-
),
180-
],
162+
[str(changelog_file_1), str(changelog_file_2)],
181163
)
182164

183165
def test_invalid_changelog(self):
166+
test_dir = Path("test") / "data" / "invalid_changelog"
184167
cfg = PumConfig()
185168
sm = SchemaMigrations(cfg)
186169
self.assertFalse(sm.exists(self.conn))
187-
upgrader = Upgrader(
188-
pg_service=self.pg_service,
189-
config=cfg,
190-
dir=str(Path("test") / "data" / "invalid_changelog"),
191-
)
170+
upgrader = Upgrader(pg_service=self.pg_service, config=cfg, dir=test_dir)
192171
with self.assertRaises(Exception) as context:
193172
upgrader.install()
194173
self.assertTrue(

0 commit comments

Comments
 (0)