vedro-spec-validator-beta 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/__init__.py +1 -0
- tests/unittest/__init__.py +1 -0
- tests/unittest/jj_spec_validator/__init__.py +1 -0
- tests/unittest/jj_spec_validator/test_output.py +106 -0
- tests/unittest/jj_spec_validator/test_spec.py +638 -0
- tests/unittest/jj_spec_validator/test_validate_spec.py +233 -0
- tests/unittest/jj_spec_validator/test_validator.py +383 -0
- vedro_spec_validator/__init__.py +6 -0
- vedro_spec_validator/__version__.py +1 -0
- vedro_spec_validator/_spec_validator.py +23 -0
- vedro_spec_validator/_spec_validator_plugin.py +163 -0
- vedro_spec_validator/jj_spec_validator/__init__.py +4 -0
- vedro_spec_validator/jj_spec_validator/_config.py +22 -0
- vedro_spec_validator/jj_spec_validator/cli.py +42 -0
- vedro_spec_validator/jj_spec_validator/output.py +13 -0
- vedro_spec_validator/jj_spec_validator/spec.py +145 -0
- vedro_spec_validator/jj_spec_validator/utils/__init__.py +6 -0
- vedro_spec_validator/jj_spec_validator/utils/_cacheir.py +45 -0
- vedro_spec_validator/jj_spec_validator/utils/_common.py +31 -0
- vedro_spec_validator/jj_spec_validator/utils/_refiner.py +99 -0
- vedro_spec_validator/jj_spec_validator/utils/_spec_matcher.py +142 -0
- vedro_spec_validator/jj_spec_validator/validate_spec.py +122 -0
- vedro_spec_validator/jj_spec_validator/validator.py +132 -0
- vedro_spec_validator_beta-0.4.0.dist-info/METADATA +208 -0
- vedro_spec_validator_beta-0.4.0.dist-info/RECORD +29 -0
- vedro_spec_validator_beta-0.4.0.dist-info/WHEEL +5 -0
- vedro_spec_validator_beta-0.4.0.dist-info/entry_points.txt +2 -0
- vedro_spec_validator_beta-0.4.0.dist-info/licenses/LICENSE +201 -0
- vedro_spec_validator_beta-0.4.0.dist-info/top_level.txt +2 -0
tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Tests package."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Unittest package."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""JJ Spec Validator unittest package."""
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import patch, Mock, call
|
|
3
|
+
import sys
|
|
4
|
+
from io import StringIO
|
|
5
|
+
|
|
6
|
+
from vedro_spec_validator.jj_spec_validator.output import output
|
|
7
|
+
from vedro_spec_validator.jj_spec_validator._config import Config
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestOutput(unittest.TestCase):
|
|
11
|
+
def setUp(self):
|
|
12
|
+
self.original_stdout = sys.stdout
|
|
13
|
+
self.stdout_mock = StringIO()
|
|
14
|
+
sys.stdout = self.stdout_mock
|
|
15
|
+
|
|
16
|
+
self.original_output_function = Config.OUTPUT_FUNCTION
|
|
17
|
+
|
|
18
|
+
def tearDown(self):
|
|
19
|
+
sys.stdout = self.original_stdout
|
|
20
|
+
|
|
21
|
+
Config.OUTPUT_FUNCTION = self.original_output_function
|
|
22
|
+
|
|
23
|
+
def test_output_with_text_and_exception(self):
|
|
24
|
+
Config.OUTPUT_FUNCTION = None
|
|
25
|
+
func_name = "test_func"
|
|
26
|
+
text = "Error message"
|
|
27
|
+
exception = Exception("Test exception")
|
|
28
|
+
|
|
29
|
+
output(func_name=func_name, text=text, e=exception)
|
|
30
|
+
|
|
31
|
+
output_content = self.stdout_mock.getvalue()
|
|
32
|
+
self.assertIn(text, output_content)
|
|
33
|
+
self.assertIn(f"Exception: {str(exception)}", output_content)
|
|
34
|
+
|
|
35
|
+
def test_output_with_exception_only(self):
|
|
36
|
+
Config.OUTPUT_FUNCTION = None
|
|
37
|
+
func_name = "test_func"
|
|
38
|
+
exception = Exception("Test exception")
|
|
39
|
+
|
|
40
|
+
output(func_name=func_name, e=exception)
|
|
41
|
+
|
|
42
|
+
output_content = self.stdout_mock.getvalue()
|
|
43
|
+
self.assertIn(f"Exception: {str(exception)}", output_content)
|
|
44
|
+
self.assertNotIn("None", output_content)
|
|
45
|
+
|
|
46
|
+
def test_output_with_text_only(self):
|
|
47
|
+
Config.OUTPUT_FUNCTION = None
|
|
48
|
+
func_name = "test_func"
|
|
49
|
+
text = "Info message"
|
|
50
|
+
|
|
51
|
+
output(func_name=func_name, text=text)
|
|
52
|
+
|
|
53
|
+
output_content = self.stdout_mock.getvalue()
|
|
54
|
+
self.assertIn(text, output_content)
|
|
55
|
+
self.assertNotIn("Exception", output_content)
|
|
56
|
+
|
|
57
|
+
def test_output_with_custom_function(self):
|
|
58
|
+
mock_output_function = Mock()
|
|
59
|
+
Config.OUTPUT_FUNCTION = mock_output_function
|
|
60
|
+
|
|
61
|
+
func_name = "test_func"
|
|
62
|
+
text = "Custom message"
|
|
63
|
+
exception = Exception("Custom exception")
|
|
64
|
+
|
|
65
|
+
output(func_name=func_name, text=text, e=exception)
|
|
66
|
+
|
|
67
|
+
mock_output_function.assert_called_once_with(func_name, text, exception)
|
|
68
|
+
|
|
69
|
+
output_content = self.stdout_mock.getvalue()
|
|
70
|
+
self.assertEqual("", output_content)
|
|
71
|
+
|
|
72
|
+
def test_output_with_empty_inputs(self):
|
|
73
|
+
Config.OUTPUT_FUNCTION = None
|
|
74
|
+
|
|
75
|
+
output()
|
|
76
|
+
|
|
77
|
+
output_content = self.stdout_mock.getvalue()
|
|
78
|
+
self.assertIn("None\n", output_content)
|
|
79
|
+
|
|
80
|
+
def test_output_with_func_name_only(self):
|
|
81
|
+
Config.OUTPUT_FUNCTION = None
|
|
82
|
+
func_name = "test_func"
|
|
83
|
+
|
|
84
|
+
output(func_name=func_name)
|
|
85
|
+
|
|
86
|
+
output_content = self.stdout_mock.getvalue()
|
|
87
|
+
self.assertIn("None\n", output_content)
|
|
88
|
+
self.assertNotIn(func_name, output_content)
|
|
89
|
+
|
|
90
|
+
@patch('builtins.print')
|
|
91
|
+
def test_output_print_called_correctly(self, mock_print):
|
|
92
|
+
Config.OUTPUT_FUNCTION = None
|
|
93
|
+
func_name = "test_func"
|
|
94
|
+
text = "Message"
|
|
95
|
+
exception = Exception("Test exception")
|
|
96
|
+
|
|
97
|
+
output(func_name=func_name, text=text, e=exception)
|
|
98
|
+
output(func_name=func_name, text=text)
|
|
99
|
+
output(func_name=func_name, e=exception)
|
|
100
|
+
|
|
101
|
+
self.assertEqual(mock_print.call_count, 3)
|
|
102
|
+
mock_print.assert_has_calls([
|
|
103
|
+
call(f"{text}\nException: {str(exception)}\n"),
|
|
104
|
+
call(f"{text}\n"),
|
|
105
|
+
call(f"\nException: {str(exception)}\n")
|
|
106
|
+
])
|