pmbootstrap-meow/test/test_file.py
Caleb Connolly 34dd9d42ba
WIP: start ripping out args (MR 2252)
Cease merging pmbootstrap.cfg into args, implement a Context type to let
us pull globals out of thin air (as an intermediate workaround) and rip
args out of a lot of the codebase.

This is just a first pass, after this we can split all the state that
leaked over into Context into types with narrower scopes (like a
BuildContext(), etc).

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00

37 lines
980 B
Python

# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import sys
import time
from pmb.types import PmbArgs
import pytest
import pmb_test # noqa
import pmb.helpers.git
import pmb.helpers.logging
import pmb.parse.version
@pytest.fixture
def args(request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "chroot"]
args = pmb.parse.arguments()
args.log = get_context().config.work / "log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(pmb.helpers.logging.logfd.close)
return args
def test_file_is_older_than(args: PmbArgs, tmpdir):
# Create a file last modified 10s ago
tempfile = str(tmpdir) + "/test"
pmb.helpers.run.user(["touch", tempfile])
past = time.time() - 10
os.utime(tempfile, (-1, past))
# Check the bounds
func = pmb.helpers.file.is_older_than
assert func(tempfile, 9) is True
assert func(tempfile, 10) is True
assert func(tempfile, 11) is False