<commit_before>from unittest.mock import MagicMock

from ereuse_workbench.computer import Computer, DataStorage, NetworkAdapter, Processor, RamModule
from tests.assertions import has_ram
from tests.conftest import computer

"""
Tests computers that broke the Workbench at one point in time.

These tests use the output of LSHW from those computers.

[1]: http://eu.crucial.com/eur/en/support-memory-speeds-compatibility
"""


# todo wireless NetworkAdaptors don't have speed (ex. 54Mbps)


def test_box_xavier(lshw: MagicMock):
    computer(lshw, 'box-xavier')


def test_eee_pc(lshw: MagicMock):
    pc, components = computer(lshw, 'eee-pc')
    assert len(components['Processor']) == 1
    assert has_ram(components)
    assert pc.model == '1000H', 'Model has noise enclosed between parenthesis'
    assert pc.serial_number == '8BOAAQ191999'
    assert pc.chassis == 'Netbook'
    assert isinstance(pc, Computer)
    assert len(components['GraphicCard']) == 1
    eth, wifi = components[NetworkAdapter.__name__]
    assert not eth.wireless
    assert wifi.wireless
    # todo assert components == jsonf('eee-pc-components-output')


def test_lenovo(lshw: MagicMock):
    pc, components = computer(lshw, 'lenovo')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'


def test_pc_laudem(lshw: MagicMock):
    # todo fix
    pc, components = computer(lshw, 'pc-laudem')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 1


def test_virtualbox_client(lshw: MagicMock):
    """
    Tests a virtualized computer.

    Virtualized computers return much lesser information as they cannot
    directly access directly the hardware of the host machine.
    """
    pc, components = computer(lshw, 'virtualbox-client')


def test_xeon(lshw: MagicMock):
    pc, components = computer(lshw, 'xeon')
    assert 'HardDrive' not in components
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 2
    ram0, ram1 = components['GraphicCard']
    assert ram0.serial_number is ram1.serial_number is None
    assert ram0.model == 'GT200GL Quadro FX 3800'
    assert ram1.model == 'GF100GL Quadro 4000'
    assert ram0.manufacturer == ram1.manufacturer == 'NVIDIA Corporation'


def test_xiaomi(lshw: MagicMock):
    pc, components = computer(lshw, 'xiaomi')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 2
    ram0, ram1 = components['GraphicCard']
    assert ram0.model == 'Sky Lake Integrated Graphics'
    assert ram0.serial_number is None
    assert ram0.manufacturer == 'Intel Corporation'
    assert ram1.model == 'NVIDIA Corporation'
    assert ram1.serial_number is None
    assert ram1.manufacturer == 'NVIDIA Corporation'
    # todo pc has ethernet capabilities through USB3 type C
    # how do we reflect this?
    wifi = components[NetworkAdapter.__name__][0]
    assert wifi.wireless


def test_dell(lshw: MagicMock):
    pc, components = computer(lshw, 'dell-logicalname-network')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 1


def test_hp_dc7900(lshw: MagicMock):
    """Tests an HP DC 7900 with an erased HDD following HMG IS5."""
    # todo check totalSlots and usedSlots
    pc, components = computer(lshw, 'erased-i5.lshw')<commit_msg>Add todo<commit_after>from unittest.mock import MagicMock

from ereuse_workbench.computer import Computer, DataStorage, NetworkAdapter, Processor, RamModule
from tests.assertions import has_ram
from tests.conftest import computer

"""
Tests computers that broke the Workbench at one point in time.

These tests use the output of LSHW from those computers.

[1]: http://eu.crucial.com/eur/en/support-memory-speeds-compatibility
"""


# todo wireless NetworkAdaptors don't have speed (ex. 54Mbps)


def test_box_xavier(lshw: MagicMock):
    computer(lshw, 'box-xavier')


def test_eee_pc(lshw: MagicMock):
    pc, components = computer(lshw, 'eee-pc')
    assert len(components['Processor']) == 1
    assert has_ram(components)
    assert pc.model == '1000H', 'Model has noise enclosed between parenthesis'
    assert pc.serial_number == '8BOAAQ191999'
    assert pc.chassis == 'Netbook'
    assert isinstance(pc, Computer)
    assert len(components['GraphicCard']) == 1
    eth, wifi = components[NetworkAdapter.__name__]
    assert not eth.wireless
    assert wifi.wireless
    # todo assert components == jsonf('eee-pc-components-output')


def test_lenovo(lshw: MagicMock):
    pc, components = computer(lshw, 'lenovo')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'


def test_pc_laudem(lshw: MagicMock):
    # todo fix
    pc, components = computer(lshw, 'pc-laudem')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 1


def test_virtualbox_client(lshw: MagicMock):
    """
    Tests a virtualized computer.

    Virtualized computers return much lesser information as they cannot
    directly access directly the hardware of the host machine.
    """
    pc, components = computer(lshw, 'virtualbox-client')


def test_xeon(lshw: MagicMock):
    pc, components = computer(lshw, 'xeon')
    assert 'HardDrive' not in components
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 2
    ram0, ram1 = components['GraphicCard']
    assert ram0.serial_number is ram1.serial_number is None
    assert ram0.model == 'GT200GL Quadro FX 3800'
    assert ram1.model == 'GF100GL Quadro 4000'
    assert ram0.manufacturer == ram1.manufacturer == 'NVIDIA Corporation'


def test_xiaomi(lshw: MagicMock):
    pc, components = computer(lshw, 'xiaomi')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 2
    ram0, ram1 = components['GraphicCard']
    assert ram0.model == 'Sky Lake Integrated Graphics'
    assert ram0.serial_number is None
    assert ram0.manufacturer == 'Intel Corporation'
    assert ram1.model == 'NVIDIA Corporation'
    assert ram1.serial_number is None
    assert ram1.manufacturer == 'NVIDIA Corporation'
    # todo pc has ethernet capabilities through USB3 type C
    # how do we reflect this?
    wifi = components[NetworkAdapter.__name__][0]
    assert wifi.wireless
    # todo data storage is not detected! (Pci express data storage)


def test_dell(lshw: MagicMock):
    pc, components = computer(lshw, 'dell-logicalname-network')
    assert len(components['Processor']) == 1
    assert has_ram(components), 'Computer without RAM'
    assert len(components['GraphicCard']) == 1


def test_hp_dc7900(lshw: MagicMock):
    """Tests an HP DC 7900 with an erased HDD following HMG IS5."""
    # todo check totalSlots and usedSlots
    pc, components = computer(lshw, 'erased-i5.lshw')
{'fraction_non_alphanumeric': 0.10476056733604831, 'fraction_numerical': 0.018536722370453586, 'mean_word_length': 4.263858093126386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033122', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2150, 'n_words': 646}