File: test_cli.py

package info (click to toggle)
python-sphobjinv 2.3.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,328 kB
  • sloc: python: 4,194; makefile: 29; sh: 20
file content (578 lines) | stat: -rw-r--r-- 22,033 bytes parent folder | download
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
r"""*CLI tests for* ``sphobjinv``.

``sphobjinv`` is a toolkit for manipulation and inspection of
Sphinx |objects.inv| files.

**Author**
    Brian Skinn (brian.skinn@gmail.com)

**File Created**
    20 Mar 2019

**Copyright**
    \(c) Brian Skinn 2016-2025

**Source Repository**
    http://www.github.com/bskinn/sphobjinv

**Documentation**
    https://sphobjinv.readthedocs.io/en/stable

**License**
    Code: `MIT License`_

    Docs & Docstrings: |CC BY 4.0|_

    See |license_txt|_ for full license terms.

**Members**

"""

import json
import re
import shlex
import subprocess as sp  # noqa: S404
from itertools import product
from pathlib import Path

import pytest
#from stdio_mgr import stdio_mgr

from sphobjinv import HeaderFields
from sphobjinv import Inventory
from sphobjinv import SourceTypes


CLI_TEST_TIMEOUT = 2
CLI_CMDS = ["sphobjinv", "python3 -m sphobjinv"]

pytestmark = [pytest.mark.cli, pytest.mark.local]


class TestMisc:
    """Tests for miscellaneous CLI functions."""

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.parametrize("cmd", CLI_CMDS)
    def test_cli_invocations(self, cmd):
        """Confirm that actual shell invocations do not error."""
        runargs = shlex.split(cmd)
        runargs.append("--help")

        out = sp.check_output(" ".join(runargs), shell=True).decode()  # noqa: S602

        assert "sphobjinv" in out
        assert "suggest" in out

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_cli_version_exits_ok(self, run_cmdline_test):
        """Confirm --version exits cleanly."""
        run_cmdline_test(["-v"])

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_noargs_shows_help(self, run_cmdline_test):
        """Confirm help shown when invoked with no arguments."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test([])

            assert "usage: sphobjinv" in out_.getvalue()

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_no_subparser_prs_exit(self, run_cmdline_test):
        """Confirm exit code 2 if option passed but no subparser provided."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["--foo"], expect=2)

            assert "error: No subparser selected" in err_.getvalue()

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_bad_subparser_prs_exit(self, run_cmdline_test):
        """Confirm exit code 2 if invalid subparser provided."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["foo"], expect=2)

            assert "invalid choice: 'foo'" in err_.getvalue()


class TestConvertGood:
    """Tests for expected-good convert functionality."""

    @pytest.mark.parametrize(
        ["out_ext", "cli_arg"],
        [(".txt", "plain"), (".inv", "zlib"), (".json", "json")],
        ids=(lambda i: "" if i.startswith(".") else i),
    )
    @pytest.mark.parametrize(
        "in_ext", [".txt", ".inv", ".json"], ids=(lambda i: i.split(".")[-1])
    )
    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_cli_convert_default_outname(
        self,
        in_ext,
        out_ext,
        cli_arg,
        scratch_path,
        run_cmdline_test,
        decomp_cmp_test,
        sphinx_load_test,
        misc_info,
    ):
        """Confirm cmdline conversions with only input file arg."""
        if in_ext == out_ext:
            pytest.skip("Ignore no-change conversions")

        src_path = scratch_path / (misc_info.FNames.INIT + in_ext)
        dest_path = scratch_path / (misc_info.FNames.INIT + out_ext)

        assert src_path.is_file()
        assert dest_path.is_file()

        dest_path.unlink()

        cli_arglist = ["convert", cli_arg, str(src_path)]
        run_cmdline_test(cli_arglist)
        assert dest_path.is_file()

        if cli_arg == "zlib":
            sphinx_load_test(dest_path)
        if cli_arg == "plain":
            decomp_cmp_test(dest_path)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT * 2)
    def test_cli_convert_expandcontract(
        self, scratch_path, misc_info, run_cmdline_test
    ):
        """Confirm cmdline contract decompress of zlib with input file arg."""
        cmp_path = scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.CMP)
        dec_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.DEC)
        recmp_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.CMP)

        run_cmdline_test(["convert", "plain", "-e", str(cmp_path), str(dec_path)])
        assert dec_path.is_file()

        run_cmdline_test(["convert", "zlib", "-c", str(dec_path), str(recmp_path)])
        assert recmp_path.is_file()

    @pytest.mark.parametrize(
        "dst_name", [True, False], ids=(lambda v: "dst_name" if v else "no_dst_name")
    )
    @pytest.mark.parametrize(
        "dst_path", [True, False], ids=(lambda v: "dst_path" if v else "no_dst_path")
    )
    @pytest.mark.parametrize(
        "src_path", [True, False], ids=(lambda v: "src_path" if v else "no_src_path")
    )
    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_cli_convert_various_pathargs(
        self,
        src_path,
        dst_path,
        dst_name,
        scratch_path,
        misc_info,
        run_cmdline_test,
        decomp_cmp_test,
        monkeypatch,
    ):
        """Confirm the various src/dest path/file combinations work."""
        init_dst_fname = misc_info.FNames.INIT + misc_info.Extensions.DEC
        mod_dst_fname = misc_info.FNames.MOD + misc_info.Extensions.DEC

        src_path = (scratch_path.resolve() if src_path else Path(".")) / (
            misc_info.FNames.INIT + misc_info.Extensions.CMP
        )
        dst_path = (scratch_path.resolve() if dst_path else Path(".")) / (
            mod_dst_fname if dst_name else ""
        )

        full_dst_path = scratch_path.resolve() / (
            mod_dst_fname if dst_name else init_dst_fname
        )

        assert (scratch_path / init_dst_fname).is_file()
        (scratch_path / init_dst_fname).unlink()

        with monkeypatch.context() as m:
            m.chdir(scratch_path)
            run_cmdline_test(["convert", "plain", str(src_path), str(dst_path)])
            assert full_dst_path.is_file()

        decomp_cmp_test(full_dst_path)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT * 50 * 3)
    @pytest.mark.testall
    def test_cli_convert_cycle_formats(
        self,
        testall_inv_path,
        res_path,
        scratch_path,
        run_cmdline_test,
        misc_info,
        pytestconfig,
        check,
    ):
        """Confirm conversion in a loop, reading/writing all formats."""
        res_src_path = res_path / testall_inv_path
        plain_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.DEC)
        json_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.JSON)
        zlib_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.CMP)

        if (
            not pytestconfig.getoption("--testall")
            and testall_inv_path.name != "objects_attrs.inv"
        ):
            pytest.skip("'--testall' not specified")

        run_cmdline_test(["convert", "plain", str(res_src_path), str(plain_path)])
        run_cmdline_test(["convert", "json", str(plain_path), str(json_path)])
        run_cmdline_test(["convert", "zlib", str(json_path), str(zlib_path)])

        invs = {
            "orig": Inventory(str(res_src_path)),
            "plain": Inventory(str(plain_path)),
            "zlib": Inventory(str(zlib_path)),
            "json": Inventory(json.loads(json_path.read_text())),
        }

        for fmt, attrib in product(
            ("plain", "zlib", "json"),
            (
                HeaderFields.Project.value,
                HeaderFields.Version.value,
                HeaderFields.Count.value,
            ),
        ):
            check.equal(getattr(invs[fmt], attrib), getattr(invs["orig"], attrib))

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_overwrite_prompt_and_behavior(
        self, res_path, scratch_path, misc_info, run_cmdline_test
    ):
        """Confirm overwrite prompt works properly."""
        src_path_1 = res_path / "objects_attrs.inv"
        src_path_2 = res_path / "objects_sarge.inv"
        dst_path = scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.DEC)
        dst_path.unlink()

        args = ["convert", "plain", None, str(dst_path)]

        # Initial decompress
        args[2] = str(src_path_1)
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(args)

            assert "converted" in err_.getvalue()
            assert "(plain)" in err_.getvalue()

        # First overwrite, declining clobber
        args[2] = str(src_path_2)
        with stdio_mgr("n\n") as (in_, out_, err_):
            run_cmdline_test(args)

            assert "(Y/N)? n" in out_.getvalue()

        assert "attrs" == Inventory(str(dst_path)).project

        # Second overwrite, with clobber
        with stdio_mgr("y\n") as (in_, out_, err_):
            run_cmdline_test(args)

            assert "(Y/N)? y" in out_.getvalue()

        assert "Sarge" == Inventory(str(dst_path)).project

    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_stdin_clobber(
        self, res_path, scratch_path, misc_info, run_cmdline_test
    ):
        """Confirm clobber with stdin data only with --overwrite."""
        src_path_sarge = res_path / "objects_sarge.inv"
        dst_path = scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.CMP)

        assert "attrs" == Inventory(dst_path).project

        data = json.dumps(Inventory(src_path_sarge).json_dict())

        args = ["convert", "plain", "-", str(dst_path)]
        with stdio_mgr(data):
            run_cmdline_test(args)
        assert "attrs" == Inventory(dst_path).project

        args.append("-o")
        with stdio_mgr(data):
            run_cmdline_test(args)
        assert "Sarge" == Inventory(dst_path).project

    def test_cli_json_no_metadata_url(
        self, res_cmp, scratch_path, misc_info, run_cmdline_test
    ):
        """Confim JSON generated from local inventory has no url in metadata."""
        json_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.JSON)

        run_cmdline_test(
            ["convert", "json", str(res_cmp.resolve()), str(json_path.resolve())]
        )

        d = json.loads(json_path.read_text())

        assert "url" not in d.get("metadata", {})

    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_json_export_import(
        self, res_cmp, scratch_path, misc_info, run_cmdline_test, sphinx_load_test
    ):
        """Confirm JSON sent to stdout from local source imports ok."""
        mod_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.CMP)

        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["convert", "json", str(res_cmp.resolve()), "-"])

            data = out_.getvalue()

        with stdio_mgr(data) as (in_, out_, err_):
            run_cmdline_test(["convert", "zlib", "-", str(mod_path.resolve())])

        assert Inventory(json.loads(data))
        assert Inventory(mod_path)
        sphinx_load_test(mod_path)


class TestSuggestGood:
    """Tests for expected-good suggest-mode functionality."""

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_noresults(self, run_cmdline_test, res_cmp):
        """Confirm suggest w/no found results works."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", "-t", "99"])
            assert "No results found" in err_.getvalue()

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_nameonly(self, run_cmdline_test, res_cmp):
        """Confirm name-only suggest works."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", "-t", "50"])
            assert re.search("^.*instance_of.*$", out_.getvalue(), re.M)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_withindex(self, run_cmdline_test, res_cmp):
        """Confirm with_index suggest works."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", "-it", "50"])
            assert re.search("^.*instance_of\\S*\\s+82\\s*$", out_.getvalue(), re.M)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_withscore(self, run_cmdline_test, res_cmp):
        """Confirm with_score suggest works."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", "-st", "50"])
            re.search("^.*instance_of\\S*\\s+\\d+\\s*$", out_.getvalue(), re.M)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_withscoreandindex(self, run_cmdline_test, res_cmp):
        """Confirm with_index + with_score suggest works."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", "-sit", "50"])
            re.search("^.*instance_of\\S*\\s+\\d+\\s+82\\s*$", out_.getvalue(), re.M)

    @pytest.mark.parametrize(
        ["inp", "flags", "nlines"],
        [("", "-at", 129), ("y\n", "-t", 130), ("n\n", "-t", 1)],
    )  # Extra line for input() query in the "y\n" case
    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_long_list(self, inp, flags, nlines, run_cmdline_test, res_cmp):
        """Confirm suggest with a long list of results works."""
        with stdio_mgr(inp) as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "instance", flags, "1"])
            assert nlines == out_.getvalue().count("\n")

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_many_results_stdin(self, res_cmp, run_cmdline_test):
        """Confirm suggest from stdin doesn't choke on a long list."""
        data = json.dumps(Inventory(res_cmp).json_dict())

        with stdio_mgr(data) as (in_, out_, err_):
            run_cmdline_test(["suggest", "-", "py", "-t", "1"])

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_suggest_paginated(self, res_cmp, run_cmdline_test):
        """Confirm pagination works as expected for a controlled example."""
        with stdio_mgr("\n" * 5) as (in_, out_, err_):
            run_cmdline_test(["suggest", res_cmp, "function", "-sapt30"])
            assert 1 < out_.getvalue().count("Press Enter to continue")


class TestFail:
    """Tests for expected-fail behaviors."""

    @pytest.mark.parametrize("with_format", [True, False])
    @pytest.mark.timeout(CLI_TEST_TIMEOUT * 2)
    def test_clifail_convert_nosrc(
        self, with_format, scratch_path, run_cmdline_test, monkeypatch
    ):
        """Confirm commandline convert w/o enough args fails."""
        monkeypatch.chdir(scratch_path)
        if with_format:
            run_cmdline_test(["convert", "plain"], expect=2)
        else:
            run_cmdline_test(["convert"], expect=2)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_clifail_convert_wrongfiletype(
        self, scratch_path, run_cmdline_test, monkeypatch
    ):
        """Confirm exit code 1 with invalid file format."""
        monkeypatch.chdir(scratch_path)
        fname = "testfile"
        Path(fname).write_bytes(b"this is not objects.inv\n")

        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["convert", "plain", fname], expect=1)
            assert "Unrecognized" in err_.getvalue()

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_clifail_convert_missingfile(self, run_cmdline_test):
        """Confirm exit code 1 with nonexistent file specified."""
        run_cmdline_test(["convert", "plain", "thisfileshouldbeabsent.txt"], expect=1)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_clifail_convert_badoutfilename(
        self, scratch_path, run_cmdline_test, misc_info
    ):
        """Confirm exit code 1 with invalid output file name."""
        run_cmdline_test(
            [
                "convert",
                "plain",
                str(scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.CMP)),
                misc_info.invalid_filename,
            ],
            expect=1,
        )

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_clifail_convert_badoutputdir(
        self, res_cmp, scratch_path, run_cmdline_test
    ):
        """Confirm exit code 1 when output location can't be created."""
        run_cmdline_test(
            [
                "convert",
                "plain",
                res_cmp,
                str(scratch_path / "nonexistent" / "folder" / "obj.txt"),
            ],
            expect=1,
        )

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_clifail_convert_pathonlysrc(self, scratch_path, run_cmdline_test):
        """Confirm cmdline plaintext convert with input directory arg fails."""
        run_cmdline_test(["convert", "plain", str(scratch_path)], expect=1)

    @pytest.mark.timeout(CLI_TEST_TIMEOUT)
    def test_clifail_convert_localfile_as_url(
        self, scratch_path, misc_info, run_cmdline_test, check
    ):
        """Confirm error when using URL mode on local file."""
        in_path = scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.CMP)

        (scratch_path / (misc_info.FNames.INIT + misc_info.Extensions.DEC)).unlink()

        with check(msg="path-style"):
            run_cmdline_test(["convert", "plain", "-u", str(in_path)], expect=1)

        with check(msg="url-style"):
            file_url = "file:///" + str(in_path.resolve())
            run_cmdline_test(["convert", "plain", "-u", file_url], expect=1)

    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_clifail_no_url_with_stdin(self, run_cmdline_test):
        """Confirm parser exit when -u passed with "-" infile."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["convert", "plain", "-u", "-"], expect=2)
            assert "--url not allowed" in err_.getvalue()


class TestStdio:
    """Tests for the stdin/stdout functionality."""

    @pytest.mark.parametrize(
        "data_format", [SourceTypes.DictJSON, SourceTypes.BytesPlaintext]
    )
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_stdio_input(
        self, scratch_path, res_cmp, misc_info, run_cmdline_test, data_format
    ):
        """Confirm that inventory data can be read on stdin."""
        inv1 = Inventory(res_cmp)

        if data_format is SourceTypes.DictJSON:
            input_data = json.dumps(inv1.json_dict())
        elif data_format is SourceTypes.BytesPlaintext:
            input_data = inv1.data_file().decode("utf-8")

        out_path = scratch_path / (misc_info.FNames.MOD + misc_info.Extensions.DEC)

        with stdio_mgr(input_data) as (in_, out_, err_):
            run_cmdline_test(["convert", "plain", "-", str(out_path.resolve())])

        inv2 = Inventory(out_path)

        assert inv1 == inv2

    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_stdio_zlib_input_fails(self, scratch_path, res_cmp, run_cmdline_test):
        """Confirm that error response is made on attempt to pipe in zlib inventory."""
        input_data = res_cmp.read_bytes().decode("latin-1")

        with stdio_mgr(input_data) as (in_, out_, err_):
            run_cmdline_test(
                ["convert", "plain", "-", str(scratch_path.resolve())], expect=1
            )

            assert "Invalid" in err_.getvalue()

    @pytest.mark.parametrize("format_arg", ["plain", "json"])
    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_stdio_output(
        self, scratch_path, res_cmp, run_cmdline_test, format_arg
    ):
        """Confirm that inventory data can be written to stdout."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["convert", format_arg, str(res_cmp.resolve()), "-"])

            result = out_.getvalue()

        inv1 = Inventory(res_cmp)

        if format_arg == "plain":
            inv2 = Inventory(result.encode("utf-8"))
        elif format_arg == "json":
            inv2 = Inventory(json.loads(result))
        else:  # pragma: no cover
            raise ValueError("Invalid parametrized format arg")

        assert inv1 == inv2

    @pytest.mark.skip(reason="Required dependency 'stdio_mgr' isn't packaged yet.")
    def test_cli_stdio_zlib_output_fails(self, res_dec, run_cmdline_test):
        """Confirm that error response is made on attempt to pipe in zlib inventory."""
        with stdio_mgr() as (in_, out_, err_):
            run_cmdline_test(["convert", "zlib", str(res_dec.resolve()), "-"], expect=1)

            assert "Error" in err_.getvalue(), err_