コード例 #1
0
ファイル: location_test.py プロジェクト: polandar/ladybug
def test_dict_methods():
    """Test JSON serialization functions"""
    city = 'Tehran'
    country = 'Iran'
    latitude = 36
    longitude = 34
    time_zone = 3.5
    elevation = 54

    loc = Location(city=city, country=country, latitude=latitude,
                   longitude=longitude, time_zone=time_zone,
                   elevation=elevation)

    assert loc.to_dict() == {"city": city, "state": '-', "country": country,
                             "latitude": latitude, "longitude": longitude,
                             "time_zone": time_zone, "elevation": elevation,
                             "station_id": None, "source": None}

    loc_from_dict = Location.from_dict(loc.to_dict())

    assert loc_from_dict.city == city
    assert loc_from_dict.latitude == latitude
    assert loc_from_dict.longitude == longitude
    assert loc_from_dict.time_zone == time_zone
    assert loc_from_dict.elevation == elevation
    assert loc_from_dict.country == country
コード例 #2
0
    def from_dict(cls, data):
        """Create a sunpath from a dictionary.

        Dictionary keys are type, location and north.
        """
        assert 'type' in data, 'type key is missing.'
        assert data[
            'type'] == 'Sunpath', 'Expected type Sunpath not %s' % data['type']

        assert 'location' in data, 'location key is missing.'
        location = Location.from_dict(data['location'])
        north = dict.get('north')
        return cls(location, north)
コード例 #3
0
import os

location_dict = {
    'city': 'Denver-Stapleton',
    'state': 'CO',
    'country': 'USA',
    'latitude': 39.76,
    'longitude': -104.86,
    'time_zone': -7.0,
    'elevation': 1611.0,
    'station_id': '724690',
    'source': 'TMY--23062',
    'type': 'Location'
}

location = Location.from_dict(location_dict)
epw_file = './tests/assets/epw/denver.epw'


def test_creation():
    sp = Sunpath(location, 10)
    assert sp.location == location
    assert sp.north == 10


def test_updating_values():
    sp = Sunpath(location)
    assert sp.north == 0
    sp.north = 10
    assert sp.north == 10
    sp.north = 0