Ejemplo n.º 1
0
    def test_codify_command(self, capsys):
        """CLI `codify` command prints correct output"""

        # With private elements
        main("codify -p pydicom::nested_priv_SQ.dcm".split())
        out, _ = capsys.readouterr()
        assert "add_new((0x0001, 0x0001)" in out

        # Without private elements
        main("codify pydicom::nested_priv_SQ.dcm".split())
        out, _ = capsys.readouterr()
        assert "add_new((0x0001, 0x0001)" not in out
Ejemplo n.º 2
0
    def test_show_command(self, capsys):
        """CLI `show` command prints correct output"""
        main("show pydicom::MR_small_RLE.dcm".split())
        out, err = capsys.readouterr()

        assert "Instance Creation Date              DA: '20040826'" in out
        assert out.endswith("OB: Array of 126 elements\n")
        assert err == ""

        # Get a specific data element
        main("show pydicom::MR_small_RLE.dcm::LargestImagePixelValue".split())
        out, _ = capsys.readouterr()
        assert "4000" == out.strip()
Ejemplo n.º 3
0
    def test_show_options(self, capsys):
        """CLI `show` command with options prints correct output"""
        # Quiet option, image file
        main("show -q pydicom::MR_small_RLE.dcm".split())
        out, err = capsys.readouterr()

        assert out.startswith("SOPClassUID: MR Image Storage")
        assert out.endswith("Rows: 64\nColumns: 64\nSliceLocation: 0.0000\n")
        assert err == ""

        # 'Quiet' option, RTPLAN file
        main("show -q pydicom::rtplan.dcm".split())
        out, err = capsys.readouterr()
        assert out.endswith(
            "Beam 1 'Field 1' TREATMENT STATIC PHOTON energy 6.00000000000000 "
            "gantry 0.0, coll 0.0, couch 0.0 "
            "(0 wedges, 0 comps, 0 boli, 0 blocks)\n")
        assert err == ""

        # Top-level-only option, also different file for more variety
        main("show -t pydicom::nested_priv_SQ.dcm".split())
        out, err = capsys.readouterr()
        assert "(0001, 0001)  Private Creator" in out
        assert "UN: b'Nested SQ'" not in out
        assert err == ""

        # Exclude private option
        main("show -x pydicom::nested_priv_SQ.dcm".split())
        out, err = capsys.readouterr()
        assert "(0001, 0001)  Private Creator" not in out
        assert err == ""
Ejemplo n.º 4
0
    def test_help(self, capsys):
        """CLI `help` command gives expected output"""
        # With subcommand
        main("help show".split())
        out, err = capsys.readouterr()
        assert out.startswith("usage: pydicom show [-h] [")
        assert err == ""

        # No subcommand following
        main(["help"])
        out, _ = capsys.readouterr()
        assert "Available subcommands:" in out

        # Non-existent subcommand following
        main("help DoesntExist".split())
        out, _ = capsys.readouterr()
        assert "Available subcommands:" in out
Ejemplo n.º 5
0
 def test_codify_data_element(self, capsys):
     """CLI `codify` command raises error if not a Dataset"""
     with pytest.raises(NotImplementedError):
         main("codify pydicom::rtplan.dcm::RTPlanLabel".split())
Ejemplo n.º 6
0
 def test_bare_command(self, capsys):
     """CLI `pydicom` with no arguments displays help"""
     main([])
     out, _ = capsys.readouterr()
     assert out.startswith("usage: pydicom [-h] {")