#! /usr/bin/env python3

"""
Unit tests for NativeUI
"""

import json
import sys

import hevclient
import numpy as np
import pytest
import sys
import json
from PySide2.QtWidgets import QApplication
import numpy as np

mmFileName = "/home/pi/hev/NativeUI/tests/integration/fixtures/HEVClient_lastData.mmap"


def test_get_updates_data_payload(nat_widget):
    """
    Currently fails because the dataSample.json is only part of the data payload.
    """
    with open("/home/pi/hev/samples/dataSample.json", "r") as f:
        data_payload = json.load(f)
        nat_widget.get_updates(data_payload)


def test_get_updates_wrong_payload(nat_widget):
    fake_payload = {
        "types": "Fake",
        "pressure": 1200000.0,
        "flow": 777000.0,
        "volume": 1.0,
    }
    with pytest.raises(KeyError):
        nat_widget.get_updates(fake_payload)


def test_must_return_0_when_q_send_cmd(nat_widget):
    assert nat_widget.q_send_cmd(str, str, float) == 0


def test_must_return_0_when_q_ack_alarm_when_out_conection(nat_widget):
    with pytest.raises(ConnectionError):
        nat_widget.q_ack_alarm(str)


def test_must_return_0_when_q_send_personal_when_out_conection(nat_widget):
    with pytest.raises(ConnectionError):
        nat_widget.q_send_personal(str)


def test_must_return_0_when__find_icons_png_directory(nat_widget):
    assert nat_widget.__find_icons("png") == "/home/pi/hev/hev-display/assets/png"


def test_must_return_0_when__find_icons_svg_directory(nat_widget):
    assert nat_widget.__find_icons("svg") == "/home/pi/hev/hev-display/assets/svg"


def test_must_return_0_when_cannot__find_icons_directory(nat_widget):
    with pytest.raises(FileNotFoundError):
        nat_widget.__find_icons("images")
