No project description provided
Project description
tempground
A script that allows you to concisely:
- create a temp directory
- fill the directory with files of known content
- run shell commands in the directory
- check the run results
For example, during unit testing of a library, we can create a temporary project that imports our library. And check that it was imported.
Example: Testing a Kotlin library
Suppose you have created a Kotlin library named mylib
. You need to test that
third-party projects can use mylib
as a dependency.
The test can be run by creating a single file like this:
# lib_test.py
from tempground import *
with TempGround(
files={
# minimalistic build script to use the library
"build.gradle.kts": """
plugins {
id("application")
kotlin("jvm") version "1.6.10"
}
repositories { mavenCentral() }
application { mainClass.set("MainKt") }
dependencies {
implementation("io.github.username:mylib")
}
""",
# additional settings, if necessary
"settings.gradle.kts": """
sourceControl {
gitRepository(java.net.URI("https://github.com/username/mylib.git")) {
producesModule("io.github.username:mylib")
}
}
""",
# kotlin code that imports and uses the library
"src/main/kotlin/Main.kt": """
import io.github.username:mylib.spanishGreeting
fun main() = println(spanishGreeting())
"""}) as app:
# running our test project
result = app.run(["gradle", "run", "-q"])
assert result.returncode == 0
assert result.stdout == "¡Hola!\n"
print("Everything is OK!")
To run the test on a clean system, install tempground
and run the script:
# assuming pip and python are Python 3.10+
# and lib_test.py is a local file
$ pip install git+https://github.com/rtmigo/tempground_py
$ python lib_test.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tempground-0.4.0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for tempground-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf593bb51c487a666826b6e86e2437209485b325ec1d94d962f7d1c2e3fe9e18 |
|
MD5 | 6405e3a2e3e842e7fe628e76a2e6108d |
|
BLAKE2b-256 | b43d1e592d54be5608da67658515a6ecba6cbd5b8dbc832bbb20a676ce75547d |