# Path: px/px_cpuinfo.py
# def get_core_count():
# def get_core_count_from_proc_cpuinfo(proc_cpuinfo="/proc/cpuinfo"):
# def get_core_count_from_sysctl():
# def parse_sysctl_output(sysctl_lines):
#     PROCESSOR_NO_PREFIX = "processor\t: "
#     CORE_ID_PREFIX = "core id\t\t: "
#     PHYSICAL_PREFIX = "hw.physicalcpu: "
#     LOGICAL_PREFIX = "hw.logicalcpu: "


import os
from px import px_cpuinfo
    my_dir = os.path.dirname(__file__)

    assert_core_counts_from_file("proc-cpuinfo-1p1l.txt", 1, 1)
    assert_core_counts_from_file("proc-cpuinfo-2p4l.txt", 2, 4)
    assert_core_counts_from_file("proc-cpuinfo-24p96l.txt", 24, 96)

    # This one is from my cell phone, just to provide a weird corner case example of things
    # we may have to handle.
    assert_core_counts_from_file("proc-cpuinfo-8p8l.txt", 8, 8)

    assert px_cpuinfo.get_core_count_from_proc_cpuinfo("/does/not/exist") is None


def test_get_core_count_from_sysctl():
    test_me = px_cpuinfo.get_core_count_from_sysctl()
    if test_me is None:
        # We're likely on Linux
        return

    # Sanity check, since we don't know the answer this is the best we can do
    physical, logical = test_me
    assert physical >= 1
    assert logical >= physical
    assert logical % physical == 0


def test_parse_sysctl_output():
    result = px_cpuinfo.parse_sysctl_output([])
    assert result == (None, None)


# Path: px/px_cpuinfo.py
# def get_core_count():
# def get_core_count_from_proc_cpuinfo(proc_cpuinfo="/proc/cpuinfo"):
# def get_core_count_from_sysctl():
# def parse_sysctl_output(sysctl_lines):
#     PROCESSOR_NO_PREFIX = "processor\t: "
#     CORE_ID_PREFIX = "core id\t\t: "
#     PHYSICAL_PREFIX = "hw.physicalcpu: "
#     LOGICAL_PREFIX = "hw.logicalcpu: "


# Path: tests/px_cpuinfo_test.py
import os
from px import px_cpuinfo

    my_dir = os.path.dirname(__file__)

    assert_core_counts_from_file("proc-cpuinfo-1p1l.txt", 1, 1)
    assert_core_counts_from_file("proc-cpuinfo-2p4l.txt", 2, 4)
    assert_core_counts_from_file("proc-cpuinfo-24p96l.txt", 24, 96)

    # This one is from my cell phone, just to provide a weird corner case example of things
    # we may have to handle.
    assert_core_counts_from_file("proc-cpuinfo-8p8l.txt", 8, 8)

    assert px_cpuinfo.get_core_count_from_proc_cpuinfo("/does/not/exist") is None


def test_get_core_count_from_sysctl():
    test_me = px_cpuinfo.get_core_count_from_sysctl()
    if test_me is None:
        # We're likely on Linux
        return

    # Sanity check, since we don't know the answer this is the best we can do
    physical, logical = test_me
    assert physical >= 1
    assert logical >= physical
    assert logical % physical == 0


def test_parse_sysctl_output():
    result = px_cpuinfo.parse_sysctl_output([])
    assert result == (None, None)


    result = px_cpuinfo.parse_sysctl_output(["gurka"])