1 import datetime

2 from ..agent_model.agents import SunAgent

3

4 class MockModel:

5 time = datetime.datetime(1900, 1, 1, 0)

6

7 class TestAgentSun:

8 def test_agent_sun_init(self):

9 """Initialize attributes properly"""

10 model = MockModel()

11 sun = SunAgent(model, 'sun')

12 for k, v in SunAgent.default_attributes.items():

13 assert sun.attributes[k] == v

14

15 def test_agent_sun_step(self):

16 # Midnight, January 1 1900 (years before '91 use '91)

17 model = MockModel()

18 sun = SunAgent(model, 'sun')

19 sun.step()

20 expected_daily_growth = SunAgent.hourly_par_fraction[0]

21 expected_monthly_growth = SunAgent.monthly_par[0]

22 assert sun.attributes['daily_growth_factor'] == expected_daily_growth

23 assert sun.attributes['monthly_growth_factor'] == expected_monthly_growth

24

25 # Noon, April 5, 1993

26 model.time = datetime.datetime(1993, 4, 5, 12)

27 sun.step()

28 expected_daily_growth = SunAgent.hourly_par_fraction[12]

29 reference_i = 12 * 2 + 3

30 expected_monthly_growth = SunAgent.monthly_par[reference_i]

31 assert sun.attributes['daily_growth_factor'] == expected_daily_growth

32 assert sun.attributes['monthly_growth_factor'] == expected_monthly_growth

33

34 # 5pm, December 31 2001 (years after '95 use '95)

35 model.time = datetime.datetime(2001, 12, 31, 17)

36 sun.step()

37 expected_daily_growth = SunAgent.hourly_par_fraction[17]

38 expected_monthly_growth = SunAgent.monthly_par[-1]

39 assert sun.attributes['daily_growth_factor'] == expected_daily_growth

40 assert sun.attributes['monthly_growth_factor'] == expected_monthly_growth