def test_invalid_string_converter(self): with self.assertRaises(ValueError) as ex: util.to_ascii_block([1, 2], 'm') self.assertIn("unsupported format character", ex.exception.args[0]) with self.assertRaises(ValueError) as ex: util.from_ascii_block("1,2,3", 'm') self.assertIn("Invalid code for converter", ex.exception.args[0])
def test_invalid_string_converter(self): with pytest.raises(ValueError) as ex: util.to_ascii_block([1, 2], "m") assert "unsupported format character" in ex.exconly() with pytest.raises(ValueError) as ex: util.from_ascii_block("1,2,3", "m") assert "Invalid code for converter" in ex.exconly()
def test_function_converter(self): values = list(range(99)) msg = 'block=ascii' tb = lambda values: util.to_ascii_block(values, str, ':'.join) fb = lambda block, cont: util.from_ascii_block(block, int, lambda s: s. split(':'), cont) self.round_trip_block_converstion(values, tb, fb, msg)
def test_function_separator(self): values = list(range(99)) fmt = "d" msg = 'block=ascii, fmt=%s' % fmt tb = lambda values: util.to_ascii_block(values, fmt, ':'.join) fb = lambda block, cont: util.from_ascii_block(block, fmt, lambda s: s. split(':'), cont) self.round_trip_block_converstion(values, tb, fb, msg)
def test_integer_ascii_block(self): values = list(range(99)) for fmt in "d": msg = "block=%s, fmt=%s" msg = msg % ("ascii", fmt) tb = lambda values: util.to_ascii_block(values, fmt, ",") fb = lambda block, cont: util.from_ascii_block(block, fmt, ",", cont) self.round_trip_block_conversion(values, tb, fb, msg)
def test_integer_ascii_block(self): values = list(range(99)) for fmt in 'd': msg = 'block=%s, fmt=%s' msg = msg % ('ascii', fmt) tb = lambda values: util.to_ascii_block(values, fmt, ',') fb = lambda block, cont: util.from_ascii_block( block, fmt, ',', cont) self.round_trip_block_converstion(values, tb, fb, msg)
def test_integer_ascii_block(self): values = list(range(99)) for fmt in 'd': msg = 'block=%s, fmt=%s' msg = msg % ('ascii', fmt) tb = lambda values: util.to_ascii_block(values, fmt, ',') fb = lambda block, cont: util.from_ascii_block(block, fmt, ',', cont) self.round_trip_block_converstion(values, tb, fb, msg)
def query_ascii_values(self, command, converter='f', separator=',', container=list, bufsize=None): """Write a string message to device and return values as iterable. Args: command: Message to be sent to device. values: Data to be written to device (as an interable) converter: String format code to be used to convert values. separator: Separator between values -- data.split(separator). container: Iterable type to use for output. bufsize: Number of bytes to read from instrument. Defaults to resource bufsize if None. Returns: Iterable of values converted from instrument response. """ if bufsize is None: bufsize = self.bufsize ascii = self.query(command, bufsize=bufsize) return from_ascii_block(ascii, convereter, separator, container)
def query_ascii_values(self, message, converter='f', separator=',', container=list): ''' Taken from pvisa.''' block = self.query(message) return from_ascii_block(block, converter, separator, container)