Skip to content

Commit 495e083

Browse files
committed
0.1.4 (2023-10-24)
------------------ * [new] vyml
1 parent 6e2260c commit 495e083

File tree

13 files changed

+213
-33
lines changed

13 files changed

+213
-33
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
CHANGELOG
55
=========
66

7+
0.1.4 (2023-10-24)
8+
------------------
9+
* [new] vyml
10+
11+
712
0.1.3 (2023-10-24)
813
------------------
914
* [new] vhelpers vdict, vlist, vparam, vre

README.rst

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ or install the package from github.com release
2626

2727
.. code:: bash
2828
29-
pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.3.tar.gz
29+
pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.4.tar.gz
3030
3131
or install the package from github.com repository
3232

@@ -292,4 +292,60 @@ Return
292292
assert vre.find4(pattern="a(b)(c)(d)(e)", string="abcde") == ("b", "c", "d", "e")
293293
294294
295+
vyml
296+
====
297+
Helpers for YAML processing.
298+
299+
300+
host_cmds(items)
301+
----------------
302+
Create commands in YAML format. Where the hostname is the key and the list of commands is the value.
303+
304+
=========== =========================================== ============================================
305+
Parameter Type Description
306+
=========== =========================================== ============================================
307+
items *List[Tuple[str, str, Union[str, List[str]* List of tuples that contain: hostname, parent command, children commands.
308+
=========== =========================================== ============================================
309+
310+
Return
311+
*str* YAML formatted commands.
312+
313+
.. code:: python
314+
315+
from vhelpers import vyml
316+
317+
# Create commands in YAML format.
318+
items = [("router1", "interface Ethernet1/1", ["description text", "shutdown"])]
319+
result = """
320+
---
321+
router1: |
322+
interface Ethernet1/1
323+
description text
324+
shutdown
325+
""".strip()
326+
assert vyml.host_cmds(items) == result
327+
328+
329+
cmd_cmds(cmd, cmds)
330+
-------------------
331+
Join parent command and children commands using indentation.
332+
333+
=========== ====================== =================================================================
334+
Parameter Type Description
335+
=========== ====================== =================================================================
336+
cmd *str* Parent command.
337+
cmds *Union[str, List[str]* Children commands.
338+
=========== ====================== =================================================================
339+
340+
Return
341+
*str* YAML formatted commands with indentation.
342+
343+
.. code:: python
344+
345+
from vhelpers import vyml
346+
347+
result = """ interface Ethernet1/1\n description text\n shutdown"""
348+
assert vyml.cmd_cmds(cmd="interface Ethernet1/1", cmds=["description text", "shutdown"]) == result
349+
350+
295351
.. _`./examples`: ./examples

examples/vyml_.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Examples vdict.py."""
2+
3+
from vhelpers import vyml
4+
5+
# Create commands in YAML format.
6+
items = [("router1", "interface Ethernet1/1", ["description text", "shutdown"])]
7+
result = """
8+
---
9+
router1: |
10+
interface Ethernet1/1
11+
description text
12+
shutdown
13+
""".strip()
14+
assert vyml.host_cmds(items) == result
15+
16+
# Join parent command and children commands using indentation.
17+
result = """ interface Ethernet1/1\n description text\n shutdown"""
18+
assert vyml.cmd_cmds(cmd="interface Ethernet1/1", cmds=["description text", "shutdown"]) == result

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "vhelpers"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "Often used functions in vladimirs-git projects"
55
authors = ["Vladimir Prusakov <[email protected]>"]
66
readme = "README.rst"
@@ -9,8 +9,7 @@ homepage = "https://github.com/vladimirs-git/vhelpers"
99
repository = "https://github.com/vladimirs-git/vhelpers"
1010
keywords = []
1111
classifiers = [
12-
"Development Status :: 1 - Planning",
13-
# "Development Status :: 5 - Production/Stable",
12+
"Development Status :: 5 - Production/Stable",
1413
"Intended Audience :: Developers",
1514
"License :: OSI Approved :: MIT License",
1615
"Programming Language :: Python :: 3.8",
@@ -42,7 +41,7 @@ test = ["pytest"]
4241

4342
[tool.poetry.urls]
4443
"Bug Tracker" = "https://github.com/vladimirs-git/vhelpers/issues"
45-
"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.3.tar.gz"
44+
"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.4.tar.gz"
4645

4746

4847
[build-system]

tests/test__package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
PYPROJECT_D = vdict.pyproject_d(ROOT)
1010

1111

12-
def test_version__readme():
12+
def test__version__readme():
1313
"""Version in README, URL."""
1414
package = PYPROJECT_D["tool"]["poetry"]["name"].replace("_", "-")
1515
readme_file = PYPROJECT_D["tool"]["poetry"]["readme"]
@@ -33,7 +33,7 @@ def test_version__readme():
3333
assert is_regex_found is True, f"absent {version_exp} in {source}"
3434

3535

36-
def test_version__changelog():
36+
def test__version__changelog():
3737
"""Version in CHANGELOG."""
3838
version_toml = PYPROJECT_D["tool"]["poetry"]["version"]
3939
path = Path.joinpath(ROOT, "CHANGELOG.rst")
@@ -43,7 +43,7 @@ def test_version__changelog():
4343
assert version_toml == version_log, f"version in {path=}"
4444

4545

46-
def test_last_modified_date():
46+
def test__last_modified_date():
4747
"""Last modified date in CHANGELOG."""
4848
path = Path.joinpath(ROOT, "CHANGELOG.rst")
4949
text = path.read_text(encoding="utf-8")

tests/test_vdict.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@
55

66
from vhelpers import vdict
77

8-
POP = [
9-
(1, {1: 2}, 2),
10-
(2, {1: 2}, None),
11-
]
12-
138
ROOT = Path(__file__).parent.parent
14-
PYPROJECT_D = [
15-
(ROOT, "vhelpers"),
16-
(str(ROOT), "vhelpers"),
17-
]
189

1910

20-
@pytest.mark.parametrize("key, data, expected", POP)
21-
def test_pop(key, data, expected):
11+
@pytest.mark.parametrize("key, data, expected", [
12+
(1, {1: 2}, 2),
13+
(2, {1: 2}, None),
14+
])
15+
def test__pop(key, data, expected):
2216
"""pop."""
2317
actual = vdict.pop(key=key, data=data)
2418
assert actual == expected
2519

2620

27-
@pytest.mark.parametrize("root, expected", PYPROJECT_D)
28-
def test_pyproject_d(root, expected):
21+
@pytest.mark.parametrize("root, expected", [
22+
(ROOT, "vhelpers"),
23+
(str(ROOT), "vhelpers"),
24+
])
25+
def test__pyproject_d(root, expected):
2926
"""pyproject_d."""
3027
data = vdict.pyproject_d(root=root)
3128
actual = data["tool"]["poetry"]["name"]

tests/test_vlist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
@pytest.mark.parametrize("items, expected", FROM_ANY)
34-
def test_from_any(items, expected):
34+
def test__from_any(items, expected):
3535
"""from_any."""
3636
actual = vlist.from_any(items=items)
3737
if isinstance(items, set):
@@ -40,7 +40,7 @@ def test_from_any(items, expected):
4040

4141

4242
@pytest.mark.parametrize("items, expected", NO_DUPL)
43-
def test_no_dupl(items, expected):
43+
def test__no_dupl(items, expected):
4444
"""no_dupl."""
4545
actual = vlist.no_dupl(items=items)
4646
assert actual == expected

tests/test_vparam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222

2323
@pytest.mark.parametrize("params_d, expected", FROM_DICT)
24-
def test_from_dict(params_d, expected):
24+
def test__from_dict(params_d, expected):
2525
"""from_dict."""
2626
actual = vparam.from_dict(params_d=params_d)
2727
assert actual == expected
2828

2929

3030
@pytest.mark.parametrize("params_, expected", TO_DICT)
31-
def test_to_dict(params_, expected):
31+
def test__to_dict(params_, expected):
3232
"""to_dict."""
3333
actual = vparam.to_dict(params=params_)
3434
assert actual == expected

tests/test_vre.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,56 @@
5151

5252

5353
@pytest.mark.parametrize("pattern, string, flags, expected", FIND1)
54-
def test_find1(pattern, string, flags, expected):
54+
def test__find1(pattern, string, flags, expected):
5555
"""find1."""
5656
actual = vre.find1(pattern=pattern, string=string, flags=flags)
5757
assert actual == expected
5858

5959

6060
@pytest.mark.parametrize("pattern, string, flags, error", ERRORS)
61-
def test_find1__invalid(pattern, string, flags, error):
61+
def test__find1__invalid(pattern, string, flags, error):
6262
"""find1."""
6363
with pytest.raises(error):
6464
vre.find1(pattern=pattern, string=string, flags=flags)
6565

6666

6767
@pytest.mark.parametrize("pattern, string, flags, expected", FIND2)
68-
def test_find2(pattern, string, flags, expected):
68+
def test__find2(pattern, string, flags, expected):
6969
"""find2."""
7070
actual = vre.find2(pattern=pattern, string=string, flags=flags)
7171
assert actual == expected
7272

7373

7474
@pytest.mark.parametrize("pattern, string, flags, error", ERRORS)
75-
def test_find2__invalid(pattern, string, flags, error):
75+
def test__find2__invalid(pattern, string, flags, error):
7676
"""find2."""
7777
with pytest.raises(error):
7878
vre.find2(pattern=pattern, string=string, flags=flags)
7979

8080

8181
@pytest.mark.parametrize("pattern, string, flags, expected", FIND3)
82-
def test_find3(pattern, string, flags, expected):
82+
def test__find3(pattern, string, flags, expected):
8383
"""find3."""
8484
actual = vre.find3(pattern=pattern, string=string, flags=flags)
8585
assert actual == expected
8686

8787

8888
@pytest.mark.parametrize("pattern, string, flags, error", ERRORS)
89-
def test_find3__invalid(pattern, string, flags, error):
89+
def test__find3__invalid(pattern, string, flags, error):
9090
"""find3."""
9191
with pytest.raises(error):
9292
vre.find3(pattern=pattern, string=string, flags=flags)
9393

9494

9595
@pytest.mark.parametrize("pattern, string, flags, expected", FIND4)
96-
def test_find4(pattern, string, flags, expected):
96+
def test__find4(pattern, string, flags, expected):
9797
"""find4."""
9898
actual = vre.find4(pattern=pattern, string=string, flags=flags)
9999
assert actual == expected
100100

101101

102102
@pytest.mark.parametrize("pattern, string, flags, error", ERRORS)
103-
def test_find4__invalid(pattern, string, flags, error):
103+
def test__find4__invalid(pattern, string, flags, error):
104104
"""find4."""
105105
with pytest.raises(error):
106106
vre.find4(pattern=pattern, string=string, flags=flags)

tests/test_vyml.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Unittests vyml.py."""
2+
3+
import pytest
4+
5+
from vhelpers import vyml
6+
from vhelpers.types_ import UStr, LT3Strs
7+
8+
9+
@pytest.mark.parametrize("items, expected", [
10+
([], "---"),
11+
([("host1", "cmdA", "cmd1\ncmd2")],
12+
"---\nhost1: |\n cmdA\n cmd1\n cmd2"),
13+
([("host1", "cmdA", ["cmd1", "cmd2"])],
14+
"---\nhost1: |\n cmdA\n cmd1\n cmd2"),
15+
([("host1", "cmdA", ["cmd1"]), ("host1", "cmdA", ["cmd2"])],
16+
"---\nhost1: |\n cmdA\n cmd1\n cmdA\n cmd2"),
17+
([("host1", "cmdA", ["cmd1", "cmd2"]), ("host2", "cmdB", ["cmd3", "cmd4"])],
18+
"---\nhost1: |\n cmdA\n cmd1\n cmd2\nhost2: |\n cmdB\n cmd3\n cmd4"),
19+
])
20+
def test___host_cmds(items: LT3Strs, expected: str):
21+
"""host_cmds."""
22+
actual = vyml.host_cmds(items=items)
23+
assert actual == expected
24+
25+
26+
@pytest.mark.parametrize("cmd, cmds, expected", [
27+
("", [], ""),
28+
("", ["cmd1"], " cmd1"),
29+
("cmdA", ["cmd1"], " cmdA\n cmd1"),
30+
("cmdA", ["cmd1", "cmd2"], " cmdA\n cmd1\n cmd2"),
31+
])
32+
def test___cmd_cmds(cmd: str, cmds: UStr, expected: str):
33+
"""cmd_cmds."""
34+
actual = vyml.cmd_cmds(cmd=cmd, cmds=cmds)
35+
assert actual == expected

0 commit comments

Comments
 (0)