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)