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)
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
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
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
def test_list_handle_error(self): """Test handling an error in listing resources.""" shell = VisaShell() shell.resource_manager = None temp_stdout = StringIO() with redirect_stdout(temp_stdout): shell.do_list("") output = temp_stdout.getvalue() assert "no attribute" in output
def test_complete_open(self): """Test providing auto-completion for open.""" shell = VisaShell() completions = shell.complete_open("TCPIP", 0, 0, 0) assert to_canonical_name( RESOURCE_ADDRESSES["TCPIP::INSTR"]) in completions # Test getting an alias from the completion completions = shell.complete_open("tcp", 0, 0, 0) assert "tcpip" in completions
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)
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)
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)
def test_complete_open(self): """Test providing auto-completion for open. """ shell = VisaShell() completions = shell.complete_open("TCPIP::", 0, 0, 0) self.assertIn(RESOURCE_ADDRESSES["TCPIP::INSTR"], completions) # Test getting an alias from the completion completions = shell.complete_open("tcp", 0, 0, 0) self.assertIn('tcpip', completions)
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)
def test_issue_in_getting_attr(self): """Test handling exception in getting an attribute.""" shell = VisaShell() shell.do_open(list(RESOURCE_ADDRESSES.values())[0]) def broken_get_visa_attribute(self, name=""): raise Exception("Exception") # Issue on VI_ old = Resource.get_visa_attribute Resource.get_visa_attribute = broken_get_visa_attribute try: temp_stdout = StringIO() with redirect_stdout(temp_stdout): try: shell.do_attr("VI_ATTR_TERMCHAR") finally: Resource.get_visa_attribute = old output = temp_stdout.getvalue() assert "Exception" in output finally: Resource.get_visa_attribute = old # Issue on aliased attr old = type(shell.current).allow_dma type(shell.current).allow_dma = property(broken_get_visa_attribute) try: temp_stdout = StringIO() with redirect_stdout(temp_stdout): shell.do_attr("allow_dma") output = temp_stdout.getvalue() assert "Exception" in output finally: type(shell.current).allow_dma = old
def test_complete_attr(self): """Test providing auto-completion for attrs.""" shell = VisaShell() shell.do_open(list(RESOURCE_ADDRESSES.values())[0]) completions = shell.complete_attr("VI_ATTR_TERM", 0, 0, 0) assert "VI_ATTR_TERMCHAR" in completions assert "VI_ATTR_TERMCHAR_EN" in completions completions = shell.complete_attr("allow_d", 0, 0, 0) assert "allow_dma" in completions
def test_getting_termchar_absent_mapping(self): """Test getting a termchar that does not map to something with a representation.""" shell = VisaShell() 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("") output = temp_stdout.getvalue() assert "Termchar read: X write: Z" == output.split("\n")[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)
def test_eof(self): """Test handling an EOF.""" shell = VisaShell() assert shell.do_EOF(None)