Example #1
0
def test__EcoDeclaration__as_resolution__resolution_is_higher_than_current__should_raise_ValueError(
        current_resolution, new_resolution):

    # Arrange
    uut = EcoDeclaration(
        emissions={},
        consumed_amount={},
        retired_amount={},
        technologies=EmissionValues(),
        resolution=current_resolution,
        utc_offset=0,
    )

    # Assert
    with pytest.raises(ValueError):
        uut.as_resolution(new_resolution, 0)
Example #2
0
def test__EcoDeclaration__as_resolution__group_by_year():

    # Arrange
    month1_day1_begin1 = datetime(2020, 1, 1, 0, 0)
    month1_day1_begin2 = datetime(2020, 1, 1, 1, 0)
    month1_day2_begin1 = datetime(2020, 1, 2, 0, 0)
    month1_day2_begin2 = datetime(2020, 1, 2, 1, 0)
    month2_day1_begin1 = datetime(2020, 2, 1, 0, 0)
    month2_day1_begin2 = datetime(2020, 2, 1, 1, 0)
    month2_day2_begin1 = datetime(2020, 2, 2, 0, 0)
    month2_day2_begin2 = datetime(2020, 2, 2, 1, 0)

    uut = EcoDeclaration(
        resolution=EcoDeclarationResolution.hour,
        utc_offset=0,
        emissions={
            month1_day1_begin1: EmissionValues(CO2=1, NO2=2),
            month1_day1_begin2: EmissionValues(CO2=3, NO2=4),
            month1_day2_begin1: EmissionValues(CO2=5, NO2=6),
            month1_day2_begin2: EmissionValues(CO2=7, NO2=8),
            month2_day1_begin1: EmissionValues(CO2=9, NO2=10),
            month2_day1_begin2: EmissionValues(CO2=11, NO2=12),
            month2_day2_begin1: EmissionValues(CO2=13, NO2=14),
            month2_day2_begin2: EmissionValues(CO2=15, NO2=16),
        },
        consumed_amount={
            month1_day1_begin1: 10,
            month1_day1_begin2: 20,
            month1_day2_begin1: 30,
            month1_day2_begin2: 40,
            month2_day1_begin1: 50,
            month2_day1_begin2: 60,
            month2_day2_begin1: 70,
            month2_day2_begin2: 80,
        },
        retired_amount={},
        technologies={
            month1_day1_begin1: EmissionValues(Solar=5, Wind=5),
            month1_day1_begin2: EmissionValues(Solar=15, Wind=5),
            month1_day2_begin1: EmissionValues(Solar=15, Wind=15),
            month1_day2_begin2: EmissionValues(Solar=35, Wind=5),
            month2_day1_begin1: EmissionValues(Solar=25, Wind=25),
            month2_day1_begin2: EmissionValues(Solar=55, Wind=5),
            month2_day2_begin1: EmissionValues(Solar=65, Wind=5),
            month2_day2_begin2: EmissionValues(Solar=75, Wind=5),
        },
    )

    # Act
    new_declaration = uut.as_resolution(EcoDeclarationResolution.year, 0)

    # Assert
    assert new_declaration.emissions == {
        datetime(2020, 1, 1, 0, 0): {
            'CO2': 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15,
            'NO2': 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16,
        },
    }

    assert new_declaration.consumed_amount == {
        datetime(2020, 1, 1, 0, 0): 10 + 20 + 30 + 40 + 50 + 60 + 70 + 80,
    }

    assert new_declaration.technologies == {
        datetime(2020, 1, 1, 0, 0): {
            'Solar': 5 + 15 + 15 + 35 + 25 + 55 + 65 + 75,
            'Wind': 5 + 5 + 15 + 5 + 25 + 5 + 5 + 5,
        },
    }