File: test_energypriceblock.py

package info (click to toggle)
python-energyzero 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,052 kB
  • sloc: python: 1,903; makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Tests for EnergyPriceBlock class."""

from datetime import UTC, datetime

import pytest

from energyzero import (
    EnergyPriceBlock,
    TimeRange,
)


def test_energy_price_block_with_costs() -> None:
    """Test EnergyPriceBlock with additional costs."""
    time_range = TimeRange(
        datetime(2025, 6, 23, 12, 0, tzinfo=UTC),
        datetime(2025, 6, 23, 13, 0, tzinfo=UTC),
    )
    block = EnergyPriceBlock(
        time_range=time_range,
        energy_price_excl=0.30,
        energy_price_incl=0.36,
        vat=0.06,
        additional_costs=[
            {"priceExcl": 0.05, "priceIncl": 0.06},
            {"priceExcl": 0.02, "priceIncl": 0.03},
        ],
    )
    assert block.total_excl == pytest.approx(0.37)
    assert block.total_incl == pytest.approx(0.45)


def test_energy_price_block_without_costs() -> None:
    """Test EnergyPriceBlock without additional costs."""
    time_range = TimeRange(
        datetime(2025, 6, 23, 12, 0, tzinfo=UTC),
        datetime(2025, 6, 23, 13, 0, tzinfo=UTC),
    )
    block = EnergyPriceBlock(
        time_range=time_range,
        energy_price_excl=0.40,
        energy_price_incl=0.48,
        vat=0.08,
        additional_costs=[],
    )
    assert block.total_excl == 0.40
    assert block.total_incl == 0.48