# Path: px/px_meminfo.py
# PAGE_SIZE_RE = re.compile(r"page size of ([0-9]+) bytes")
# SWAPUSAGE_RE = re.compile(r".*used = ([0-9.]+)M.*")
# def get_meminfo():
# def _get_ram_numbers():
# def _update_from_meminfo(base, line, name):
# def _get_ram_numbers_from_proc(proc_meminfo="/proc/meminfo"):
# def _get_ram_numbers_macos():
# def _get_vmstat_output_lines():
# def _get_used_swap_bytes_sysctl():
# def _update_if_prefix(base, line, prefix):
# def _get_ram_numbers_from_vm_stat_output(vm_stat_lines):


import os
from px import px_meminfo

def test_get_ram_numbers_from_proc_none():
    my_dir = os.path.dirname(__file__)

    info = px_meminfo._get_ram_numbers_from_proc(
        os.path.join(my_dir, "file name that doesn't exist")
    )
    assert info is None


def test_get_ram_numbers_from_proc_2010():
    my_dir = os.path.dirname(__file__)

    info = px_meminfo._get_ram_numbers_from_proc(
        os.path.join(my_dir, "proc-meminfo-2010.txt")
    )
    assert info is not None

    total_bytes, wanted_bytes = info
    assert total_bytes == 1921988 * 1024

    # From before MemAvailable's invention:
    # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
    available_kb = 1374408 + 32688 + 370540 + 0
    assert wanted_bytes == total_bytes - available_kb * 1024


def test_get_ram_numbers_from_proc_2020():
    my_dir = os.path.dirname(__file__)


# Path: px/px_meminfo.py
# PAGE_SIZE_RE = re.compile(r"page size of ([0-9]+) bytes")
# SWAPUSAGE_RE = re.compile(r".*used = ([0-9.]+)M.*")
# def get_meminfo():
# def _get_ram_numbers():
# def _update_from_meminfo(base, line, name):
# def _get_ram_numbers_from_proc(proc_meminfo="/proc/meminfo"):
# def _get_ram_numbers_macos():
# def _get_vmstat_output_lines():
# def _get_used_swap_bytes_sysctl():
# def _update_if_prefix(base, line, prefix):
# def _get_ram_numbers_from_vm_stat_output(vm_stat_lines):


# Path: tests/px_meminfo_test.py
import os
from px import px_meminfo


def test_get_ram_numbers_from_proc_none():
    my_dir = os.path.dirname(__file__)

    info = px_meminfo._get_ram_numbers_from_proc(
        os.path.join(my_dir, "file name that doesn't exist")
    )
    assert info is None


def test_get_ram_numbers_from_proc_2010():
    my_dir = os.path.dirname(__file__)

    info = px_meminfo._get_ram_numbers_from_proc(
        os.path.join(my_dir, "proc-meminfo-2010.txt")
    )
    assert info is not None

    total_bytes, wanted_bytes = info
    assert total_bytes == 1921988 * 1024

    # From before MemAvailable's invention:
    # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
    available_kb = 1374408 + 32688 + 370540 + 0
    assert wanted_bytes == total_bytes - available_kb * 1024


def test_get_ram_numbers_from_proc_2020():
    my_dir = os.path.dirname(__file__)


    info = px_meminfo._get_ram_numbers_from_proc(