forked from wwkimball/yamlpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commands_yaml_validate.py
90 lines (79 loc) · 3.02 KB
/
test_commands_yaml_validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pytest
from tests.conftest import create_temp_yaml_file
class Test_commands_yaml_validate():
"""Tests for the yaml-validate command-line tool."""
command = "yaml-validate"
def test_no_arguments(self, script_runner):
result = script_runner.run([self.command, "--nostdin"])
assert not result.success, result.stderr
assert "There must be at least one YAML_FILE" in result.stderr
def test_too_many_pseudofiles(self, script_runner):
result = script_runner.run([
self.command
, '-'
, '-'])
assert not result.success, result.stderr
assert "Only one YAML_FILE may be the - pseudo-file" in result.stderr
def test_valid_singledoc(self, script_runner, tmp_path_factory):
yaml_file = create_temp_yaml_file(tmp_path_factory, """---
this:
single-document:
is: valid
""")
result = script_runner.run([
self.command
, "--nostdin"
, yaml_file])
assert result.success, result.stderr
def test_invalid_singledoc(self, script_runner, tmp_path_factory):
yaml_file = create_temp_yaml_file(tmp_path_factory, "{[}")
result = script_runner.run([
self.command
, "--nostdin"
, yaml_file])
assert not result.success, result.stderr
assert " * YAML parsing error in" in result.stdout
def test_valid_stdin_explicit(self, script_runner, tmp_path_factory):
import subprocess
stdin_content = "{this: {is: valid}}"
result = subprocess.run(
[self.command
, "-"]
, stdout=subprocess.PIPE
, input=stdin_content
, universal_newlines=True
)
assert 0 == result.returncode, result.stderr
def test_valid_stdin_implicit(self, script_runner, tmp_path_factory):
import subprocess
stdin_content = "{this: {is: valid}}"
result = subprocess.run(
[self.command]
, stdout=subprocess.PIPE
, input=stdin_content
, universal_newlines=True
)
assert 0 == result.returncode, result.stderr
def test_invalid_stdin_explicit(self, script_runner, tmp_path_factory):
import subprocess
stdin_content = "{this: {is not: valid}]"
result = subprocess.run(
[self.command
, "-"]
, stdout=subprocess.PIPE
, input=stdin_content
, universal_newlines=True
)
assert 2 == result.returncode, result.stderr
assert " * YAML parsing error in" in result.stdout
def test_invalid_stdin_implicit(self, script_runner, tmp_path_factory):
import subprocess
stdin_content = "{this: {is not: valid}]"
result = subprocess.run(
[self.command]
, stdout=subprocess.PIPE
, input=stdin_content
, universal_newlines=True
)
assert 2 == result.returncode, result.stderr
assert " * YAML parsing error in" in result.stdout