def test_coord_default_method(): coord = hszinc.Coordinate(latitude=33.77, longitude=-77.45) ref_str = u'33.770000° lat -77.450000° long' if six.PY2: ref_str = ref_str.encode('utf-8') eq_(repr(coord), 'Coordinate(33.77, -77.45)') eq_(str(coord), ref_str)
def test_coord_ne_mycoord(): hsc = hszinc.Coordinate(latitude=33.77, longitude=-77.45) mc = MyCoordinate(-33.77, 77.45) assert hsc != mc assert mc != hsc
def test_coord_ne_notcoord(): assert (hszinc.Coordinate(latitude=33.77, longitude=-77.45) \ != (33.77, -77.45))
def test_coord_ne(): assert hszinc.Coordinate(latitude=-33.77, longitude=77.45) \ != hszinc.Coordinate(latitude=33.77, longitude=-77.45)
def test_coord_eq_mycoord(): hsc = hszinc.Coordinate(latitude=33.77, longitude=-77.45) mc = MyCoordinate(33.77, -77.45) assert hsc == mc assert mc == hsc
def test_coord_eq(): assert hszinc.Coordinate(latitude=33.77, longitude=-77.45) \ == hszinc.Coordinate(latitude=33.77, longitude=-77.45)
def test_coord_hash(): assert hash(hszinc.Coordinate(latitude=33.77, longitude=-77.45)) == \ hash(33.77) ^ hash(-77.45)
def test_data_types_json(): grid = hszinc.Grid(version=hszinc.VER_2_0) grid.column['comment'] = {} grid.column['value'] = {} grid.extend([ { 'comment': 'A null value', 'value': None, }, { 'comment': 'A marker', 'value': hszinc.MARKER, }, { 'comment': 'A boolean, indicating False', 'value': False, }, { 'comment': 'A boolean, indicating True', 'value': True, }, { 'comment': 'A reference, without value', 'value': hszinc.Ref('a-ref'), }, { 'comment': 'A reference, with value', 'value': hszinc.Ref('a-ref', 'a value'), }, { 'comment': 'A binary blob', 'value': hszinc.Bin('text/plain'), }, { 'comment': 'A quantity', 'value': hszinc.Quantity(500,'miles'), }, { 'comment': 'A quantity without unit', 'value': hszinc.Quantity(500,None), }, { 'comment': 'A coordinate', 'value': hszinc.Coordinate(-27.4725,153.003), }, { 'comment': 'A URI', 'value': hszinc.Uri('http://www.example.com'), }, { 'comment': 'A string', 'value': 'This is a test\n'\ 'Line two of test\n'\ '\tIndented with "quotes" and \\backslashes\\', }, { 'comment': 'A date', 'value': datetime.date(2016,1,13), }, { 'comment': 'A time', 'value': datetime.time(7,51,43,microsecond=12345), }, { 'comment': 'A timestamp (non-UTC)', 'value': pytz.timezone('Europe/Berlin').localize(\ datetime.datetime(2016,1,13,7,51,42,12345)), }, { 'comment': 'A timestamp (UTC)', 'value': pytz.timezone('UTC').localize(\ datetime.datetime(2016,1,13,7,51,42,12345)), }, ]) grid_json = json.loads(hszinc.dump(grid, mode=hszinc.MODE_JSON)) assert grid_json == { 'meta': {'ver':'2.0'}, 'cols': [ {'name':'comment'}, {'name':'value'}, ], 'rows': [ { 'comment': 's:A null value', 'value': None}, { 'comment': 's:A marker', 'value': 'm:'}, { 'comment': 's:A boolean, indicating False', 'value': False}, { 'comment': 's:A boolean, indicating True', 'value': True}, { 'comment': 's:A reference, without value', 'value': 'r:a-ref'}, { 'comment': 's:A reference, with value', 'value': 'r:a-ref a value'}, { 'comment': 's:A binary blob', 'value': 'b:text/plain'}, { 'comment': 's:A quantity', 'value': 'n:500.000000 miles'}, { 'comment': 's:A quantity without unit', 'value': 'n:500.000000'}, { 'comment': 's:A coordinate', 'value': 'c:-27.472500,153.003000'}, { 'comment': 's:A URI', 'value': 'u:http://www.example.com'}, { 'comment': 's:A string', 'value': 's:This is a test\n'\ 'Line two of test\n'\ '\tIndented with \"quotes\" '\ 'and \\backslashes\\'}, { 'comment': 's:A date', 'value': 'd:2016-01-13'}, { 'comment': 's:A time', 'value': 'h:07:51:43.012345'}, { 'comment': 's:A timestamp (non-UTC)', 'value': 't:2016-01-13T07:51:42.012345+01:00 Berlin'}, { 'comment': 's:A timestamp (UTC)', 'value': 't:2016-01-13T07:51:42.012345+00:00 UTC'}, ], }
def test_data_types_v2(): grid = hszinc.Grid(version=hszinc.VER_2_0) grid.column['comment'] = {} grid.column['value'] = {} grid.extend([ { 'comment': 'A null value', 'value': None, }, { 'comment': 'A marker', 'value': hszinc.MARKER, }, { 'comment': 'A "remove" object', 'value': hszinc.REMOVE, }, { 'comment': 'A boolean, indicating False', 'value': False, }, { 'comment': 'A boolean, indicating True', 'value': True, }, { 'comment': 'A reference, without value', 'value': hszinc.Ref('a-ref'), }, { 'comment': 'A reference, with value', 'value': hszinc.Ref('a-ref', 'a value'), }, { 'comment': 'A binary blob', 'value': hszinc.Bin('text/plain'), }, { 'comment': 'A quantity', 'value': hszinc.Quantity(500,'miles'), }, { 'comment': 'A quantity without unit', 'value': hszinc.Quantity(500,None), }, { 'comment': 'A coordinate', 'value': hszinc.Coordinate(-27.4725,153.003), }, { 'comment': 'A URI', 'value': hszinc.Uri(u'http://www.example.com#`unicode:\u1234\u5678`'), }, { 'comment': 'A string', 'value': u'This is a test\n'\ u'Line two of test\n'\ u'\tIndented with "quotes", \\backslashes\\ and '\ u'Unicode characters: \u1234\u5678 and a $ dollar sign', }, { 'comment': 'A date', 'value': datetime.date(2016,1,13), }, { 'comment': 'A time', 'value': datetime.time(7,51,43,microsecond=12345), }, { 'comment': 'A timestamp (non-UTC)', 'value': pytz.timezone('Europe/Berlin').localize(\ datetime.datetime(2016,1,13,7,51,42,12345)), }, { 'comment': 'A timestamp (UTC)', 'value': pytz.timezone('UTC').localize(\ datetime.datetime(2016,1,13,7,51,42,12345)), }, ]) grid_str = hszinc.dump(grid) ref_str = '''ver:"2.0" comment,value "A null value",N "A marker",M "A \\"remove\\" object",R "A boolean, indicating False",F "A boolean, indicating True",T "A reference, without value",@a-ref "A reference, with value",@a-ref "a value" "A binary blob",Bin(text/plain) "A quantity",500miles "A quantity without unit",500 "A coordinate",C(-27.472500,153.003000) "A URI",`http://www.example.com#\\`unicode:\\u1234\\u5678\\`` "A string","This is a test\\nLine two of test\\n\\tIndented with \\"quotes\\", \\\\backslashes\\\\ and Unicode characters: \\u1234\\u5678 and a \\$ dollar sign" "A date",2016-01-13 "A time",07:51:43.012345 "A timestamp (non-UTC)",2016-01-13T07:51:42.012345+01:00 Berlin "A timestamp (UTC)",2016-01-13T07:51:42.012345+00:00 UTC ''' assert grid_str == ref_str
def gen_random_coordinate(): return hszinc.Coordinate(\ gen_random_num(360)-180.0, gen_random_num(360)-180.0)
def gen_random_coordinate(): return hszinc.Coordinate( \ round(gen_random_num(360) - 180.0, 2), round(gen_random_num(360) - 180.0, 2))