|
5 | 5 | from unittest import mock |
6 | 6 |
|
7 | 7 | from codicefiscale import __version__ |
8 | | -from codicefiscale.cli import run, run_with_args |
| 8 | +from codicefiscale.cli import _validate_from_args, run, run_with_args |
9 | 9 |
|
10 | 10 |
|
11 | 11 | def assert_command_output(command, expected_output): |
@@ -588,32 +588,30 @@ def test_decode_with_wrong_code(): |
588 | 588 |
|
589 | 589 |
|
590 | 590 | def test_validate(): |
591 | | - with mock.patch("sys.stdout", new=StringIO()) as fake_output: |
592 | | - args = argparse.Namespace( |
593 | | - code="RSSMRA90A01H501W", |
594 | | - subcommand="validate", |
595 | | - ) |
596 | | - run_with_args(args) |
597 | | - output = fake_output.getvalue().strip() |
598 | | - assert output == "✅" |
| 591 | + args = argparse.Namespace( |
| 592 | + code="RSSMRA90A01H501W", |
| 593 | + subcommand="validate", |
| 594 | + ) |
| 595 | + exit_code = _validate_from_args(args) |
| 596 | + assert exit_code == 0 |
599 | 597 |
|
600 | 598 |
|
601 | 599 | def test_validate_from_command_line(): |
602 | 600 | cmd = "python -m codicefiscale validate RSSMRA90A01H501W" |
603 | | - assert_command_output(cmd, "✅") |
| 601 | + result = subprocess.run(cmd, shell=True) |
| 602 | + assert result.returncode == 0 |
604 | 603 |
|
605 | 604 |
|
606 | 605 | def test_validate_with_wrong_code(): |
607 | | - with mock.patch("sys.stdout", new=StringIO()) as fake_output: |
608 | | - args = argparse.Namespace( |
609 | | - code="RSSMRA90A01H501X", |
610 | | - subcommand="validate", |
611 | | - ) |
612 | | - run_with_args(args) |
613 | | - output = fake_output.getvalue().strip() |
614 | | - assert output == "❌" |
| 606 | + args = argparse.Namespace( |
| 607 | + code="RSSMRA90A01H501X", |
| 608 | + subcommand="validate", |
| 609 | + ) |
| 610 | + exit_code = _validate_from_args(args) |
| 611 | + assert exit_code == 1 |
615 | 612 |
|
616 | 613 |
|
617 | 614 | def test_validate_with_wrong_code_from_command_line(): |
618 | 615 | cmd = "python -m codicefiscale validate RSSMRA90A01H501X" |
619 | | - assert_command_output(cmd, "❌") |
| 616 | + result = subprocess.run(cmd, shell=True) |
| 617 | + assert result.returncode == 1 |
0 commit comments