|
17 | 17 | # 3rd party
|
18 | 18 | import click
|
19 | 19 | import pytest
|
| 20 | +from pytest_regressions.data_regression import DataRegressionFixture |
20 | 21 |
|
21 | 22 | # this package
|
22 | 23 | from domdf_python_tools.testing import testing_boolean_values
|
23 | 24 | from domdf_python_tools.typing import HasHead
|
24 | 25 | from domdf_python_tools.utils import (
|
25 | 26 | cmp,
|
26 | 27 | convert_indents,
|
| 28 | + divide, |
27 | 29 | double_repr_string,
|
28 | 30 | enquote_value,
|
29 | 31 | head,
|
|
33 | 35 | printt,
|
34 | 36 | pyversion,
|
35 | 37 | redirect_output,
|
| 38 | + redivide, |
36 | 39 | stderr_writer,
|
37 | 40 | str2tuple,
|
38 | 41 | strtobool,
|
@@ -449,3 +452,47 @@ def test_redirect_output_combine():
|
449 | 452 | expected = "I'm going to stdout\nI'm going to stderr\nI'm also going to stdout\nI'm also going to stderr\n"
|
450 | 453 | assert stdout.getvalue() == expected
|
451 | 454 | assert stderr.getvalue() == expected
|
| 455 | + |
| 456 | + |
| 457 | +@pytest.mark.parametrize( |
| 458 | + "string, sep", |
| 459 | + [ |
| 460 | + ("hello=world", '='), |
| 461 | + ("hello = world", '='), |
| 462 | + ("hello = world", " = "), |
| 463 | + ("hello: world", ':'), |
| 464 | + ("hello: world", ": "), |
| 465 | + ] |
| 466 | + ) |
| 467 | +def test_divide(string: str, sep: str, data_regression: DataRegressionFixture): |
| 468 | + data = dict(divide(e, sep) for e in [string, string, string]) |
| 469 | + |
| 470 | + data_regression.check(data) |
| 471 | + |
| 472 | + |
| 473 | +def test_divide_errors(): |
| 474 | + with pytest.raises(ValueError, match="'=' not in 'hello: world'"): |
| 475 | + divide("hello: world", '=') |
| 476 | + |
| 477 | + |
| 478 | +@pytest.mark.parametrize( |
| 479 | + "string, sep", |
| 480 | + [ |
| 481 | + ("hello=world", r"\s?=\s?"), |
| 482 | + ("hello = world", r"\s?=\s?"), |
| 483 | + ("hello = world", '='), |
| 484 | + ("hello: world", r":\s?"), |
| 485 | + ("hello: world", r"\s?:\s?"), |
| 486 | + ] |
| 487 | + ) |
| 488 | +def test_redivide(string: str, sep: str, data_regression: DataRegressionFixture): |
| 489 | + data = dict(redivide(e, sep) for e in [string, string, string]) |
| 490 | + |
| 491 | + data_regression.check(data) |
| 492 | + |
| 493 | + |
| 494 | +def test_redivide_errors(): |
| 495 | + with pytest.raises(ValueError, match=r"re.compile\('='\) has no matches in 'hello: world'"): |
| 496 | + redivide("hello: world", '=') |
| 497 | + with pytest.raises(ValueError, match=r"re.compile\(.*\) has no matches in 'hello: world'"): |
| 498 | + redivide("hello: world", r"\d") |
0 commit comments