-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --output option to list commands (supports text, json, csv …
…and yaml)
- Loading branch information
Showing
7 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import csv | ||
|
||
from io import StringIO | ||
from unittest.mock import Mock | ||
|
||
import yaml | ||
|
||
from pvecontrol.vm import PVEVm, COLUMNS | ||
from pvecontrol.utils import render_output, OutputFormats | ||
|
||
|
||
def test_render_output(): | ||
api = Mock() | ||
vms = [ | ||
PVEVm(api, "pve-node-1", 100, "running"), | ||
PVEVm(api, "pve-node-1", 101, "running"), | ||
PVEVm(api, "pve-node-2", 102, "stopped"), | ||
] | ||
|
||
output_text = render_output(vms, columns=COLUMNS, output=OutputFormats.TEXT) | ||
output_json = render_output(vms, columns=COLUMNS, output=OutputFormats.JSON) | ||
output_csv = render_output(vms, columns=COLUMNS, output=OutputFormats.CSV) | ||
output_yaml = render_output(vms, columns=COLUMNS, output=OutputFormats.YAML) | ||
|
||
assert output_text.split("\n")[0].replace("+", "").replace("-", "") == "" | ||
assert len(json.loads(output_json)) == 3 | ||
assert len(list(csv.DictReader(StringIO(output_csv)))) == 3 | ||
assert len(yaml.safe_load(output_yaml)) == 3 |