コード例 #1
0
    def test_issue_in_getting_attr(self):
        """Test handling exception in getting an attribute.

        """
        shell = VisaShell()
        shell.current = shell.do_open(list(RESOURCE_ADDRESSES.values())[0])

        def broken_get_visa_attribute(self, name):
            raise Exception()

        # Issue on VI_
        old = Resource.get_visa_attribute
        Resource.get_visa_attribute = broken_get_visa_attribute

        temp_stdout = StringIO()
        with contextlib.redirect_stdout(temp_stdout):
            try:
                shell.do_attr("VI_ATTR_TERMCHAR")
            finally:
                Resource.get_visa_attribute = old
        output = temp_stdout.getvalue()
        self.assertIn("Exception", details)

        # Issue on aliased attr
        old = type(shell.current).allow_dma
        type(shell.current).allow_dma = property(broken_get_visa_attribute)

        temp_stdout = StringIO()
        with contextlib.redirect_stdout(temp_stdout):
            try:
                shell.do_attr("allow_dma")
            finally:
                Resource.get_visa_attribute = old
        output = temp_stdout.getvalue()
        self.assertIn("Exception", details)
コード例 #2
0
    def test_print_attr_list(self):
        """Test printing attribute list.

        """
        class FalseResource:
            @classmethod
            def get_visa_attribute(cls, id):
                if id == constants.VI_ATTR_TMO_VALUE:
                    raise errors.VisaIOError(constants.VI_ERROR_NSUP_ATTR)
                elif id == constants.VI_ATTR_DMA_ALLOW_EN:
                    raise Exception("Long text: aaaaaaaaaaaaaaaaaaaa")
                else:
                    raise Exception("Test")

        FalseResource.visa_attributes_classes = Resource.visa_attribute_classes

        shell = VisaShell()
        shell.current = FalseResource

        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.print_attribute_list()

        output = temp_stdout.getvalue()
        self.assertIn('Long text:...', output)
コード例 #3
0
 def test_termchar_set_handle_error(self):
     """Test handling an error in setting the termchars."""
     shell = VisaShell()
     shell.current = True
     temp_stdout = StringIO()
     with redirect_stdout(temp_stdout):
         shell.do_termchar("CR")
     output = temp_stdout.getvalue()
     assert "no attribute" in output
コード例 #4
0
 def test_timeout_get_handle_error(self):
     """Test handling an error in getting teh timeout."""
     shell = VisaShell()
     shell.current = True
     temp_stdout = StringIO()
     with redirect_stdout(temp_stdout):
         shell.do_timeout("")
     output = temp_stdout.getvalue()
     assert "no attribute" in output
コード例 #5
0
 def test_close_handle_error(self):
     """Test handling an error while closing."""
     shell = VisaShell()
     shell.current = True
     temp_stdout = StringIO()
     with redirect_stdout(temp_stdout):
         shell.do_close("")
     output = temp_stdout.getvalue()
     assert "no attribute" in output
コード例 #6
0
    def test_termchar_get_handle_error(self):
        """Test handling error when getting the termchars.

        """
        shell = VisaShell()
        shell.current = True
        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.do_termchar("")
        output = temp_stdout.getvalue()
        self.assertIn('no attribute', output)
コード例 #7
0
    def test_timeout_set_handle_error(self):
        """Test handling an error in setting the timeout

        """
        shell = VisaShell()
        shell.current = True
        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.do_timeout("1000")
        output = temp_stdout.getvalue()
        self.assertIn('no attribute', output)
コード例 #8
0
    def test_write_handle_error(self):
        """Test handling an error in write.

        """
        shell = VisaShell()
        shell.current = True
        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.do_write("")
        output = temp_stdout.getvalue()
        self.assertIn('no attribute', output)
コード例 #9
0
ファイル: test_shell.py プロジェクト: xl-w/pyvisa
    def test_query_handle_error(self):
        """Test handling an error in query.

        """
        shell = VisaShell()
        shell.current = True
        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.do_query("")
        output = temp_stdout.getvalue()
        self.assertIn("no attribute", output)
コード例 #10
0
    def test_getting_termchar_absent_mapping(self):
        """Test getting a termchar that does not map to something with a representation.

        """
        shell = VisaShell()
        shell.current = shell.do_open(list(RESOURCE_ADDRESSES.values())[0])
        shell.current.read_termination = "X"
        shell.current.write_termination = "Z"
        temp_stdout = StringIO()
        with redirect_stdout(temp_stdout):
            shell.do_termchar("")
        self.assertSequenceEqual('Termchar read: X write: Z', output)
コード例 #11
0
    def test_complete_attr(self):
        """Test providing auto-completion for attrs.

        """
        shell = VisaShell()
        shell.current = shell.do_open(list(RESOURCE_ADDRESSES.values())[0])
        completions = shell.complete_attr("VI_ATTR_TERM", 0, 0, 0)
        self.assertIn('VI_ATTR_TERMCHAR', completions)
        self.assertIn('VI_ATTR_TERMCHAR_EN', completions)

        completions = shell.complete_attr("allow_d", 0, 0, 0)
        self.assertIn('allow_dma', completions)