def test_recursive_to_str(self): now = datetime.now() objid = ObjectId() number = 10 self.check_value_type(es.to_str(self.record)) self.check_value_type(es.to_str(self.values)) self.check_value_type(es.to_str(now)) self.check_value_type(es.to_str(objid)) self.check_value_type(es.to_str(number))
def to_str(cls, values, callback=None): """Convert many records's values to str """ if callback and callable(callback): if isinstance(values, dict): return callback(_es.to_str(values)) return [callback(_es.to_str(i)) for i in values] return _es.to_str(values)
def to_str(cls, values, callback=None): """string化的多个record组成的list对象 """ if callback and callable(callback): if isinstance(values, dict): return callback(_es.to_str(values)) return [callback(_es.to_str(i)) for i in values] return _es.to_str(values)
def test_to_str(self): data = { 'v1': 10, 'v2': datetime.datetime.now(), 'v3': ObjectId(), 'v4': 'value', } self.assertTrue(isinstance(json.dumps(escape.to_str([deepcopy(data) for i in range(10)])), basestring)) self.assertTrue(isinstance(json.dumps(escape.to_str(deepcopy(data))), basestring))
def test_json_decode(self): self.assertTrue(type(es.json_decode( es.json_encode(es.to_str(self.values), indent=4) )).__name__ == 'list' ) # error test self.assertTrue(type(es.json_decode( es.json_encode(es.to_str(self.values), invlaid=4) )).__name__ == 'NoneType' )
def test_to_str(self): data = { 'v1': 10, 'v2': datetime.datetime.now(), 'v3': ObjectId(), 'v4': 'value', } self.assertTrue(isinstance(json.dumps(escape.to_str( [deepcopy(data) for i in range(10)])), basestring)) self.assertTrue(isinstance(json.dumps( escape.to_str(deepcopy(data))), basestring))
def test_json_decode(self): self.assertTrue( type( es.json_decode(es.json_encode(es.to_str(self.values), indent=4))).__name__ == 'list') # error test self.assertTrue( type( es.json_decode( es.json_encode(es.to_str(self.values), invlaid=4))).__name__ == 'NoneType')
def test_to_str_encode(self): data = { 'v1': 10, 'v2': datetime.datetime.now(), 'v3': ObjectId(), 'v4': 'value', } v = escape.to_str(data) self.assertTrue(isinstance(v['v1'], int)) self.assertTrue(isinstance(v['v2'], float)) self.assertTrue(isinstance(v['v3'], basestring_type)) self.assertTrue(isinstance(v['v4'], basestring_type)) def encode(v): return str(v) v = escape.to_str(data, encode) self.assertTrue(isinstance(v['v1'], basestring_type)) self.assertTrue(isinstance(v['v2'], basestring_type)) self.assertTrue(isinstance(v['v3'], basestring_type)) self.assertTrue(isinstance(v['v4'], basestring_type))
def to_str(v): return _es.to_str(v)
def to_str(v): """Convert value into string """ return _es.to_str(v)
def test_json_encode(self): self.assertTrue( es.json_encode(es.to_str(self.values), indent=4) is not None)
def test_json_encode(self): self.assertTrue(es.json_encode( es.to_str(self.values), indent=4) is not None)