Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 File management #25

Open
Jelleas opened this issue Jul 17, 2023 · 0 comments
Open

V2 File management #25

Jelleas opened this issue Jul 17, 2023 · 0 comments
Labels

Comments

@Jelleas
Copy link
Owner

Jelleas commented Jul 17, 2023

With the following api:

only("hello.py")     # only hello.py will be present
include("*.csv")     # also include all csv files
exclude("foo.csv", "bar.csv")   # don't include foo.csv and bar.csv
require("qux.zip")   # make sure qux.zip exists and then include qux.zip

Calling any of these functions will create a sandbox (a temporary directory) and copy all included files over. Each subsequent call will not create another sandbox, but will move any newly included or excluded files from or to the sandbox.

The api functions can be called in the test module and inside each test. A call in the module will create one sandbox for all tests to use. Useful for any compiling or pipeline-ish operation. For example:

from checkpy import *
import os

only("foo.py")

@test()
def testFoo1():
    """Foo 1"""
    with open('pretend_result_of_foo.csv", "w") as f:
        pass

@passed(testFoo, hide=False)  # @passed is not necessary, but probably the right thing to do here
def testFoo2():
    """Foo 2"""
    assert "pretend_result_of_foo.csv" in os.listdir()

Calling an api function inside a test will create a new sandbox for the test alone. It can only copy files from the module level sandbox if that also exists. test-level calls are useful for ensuring a clean slate for each test and for controlling files per test. For example:

from checkpy import *
import os

only("foo.py", "bar.py")

@test()
def testFoo():
    """Foo works"""
    only("foo.py")  # cannot include "qux.py" here because of module level sandbox
    assert os.listdir() == ["foo.py"]
@Jelleas Jelleas moved this to Todo in checkpy v2 Jul 17, 2023
@Jelleas Jelleas moved this from Todo to Done in checkpy v2 Jul 17, 2023
@Jelleas Jelleas added the v2 label Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant