add tests

This commit is contained in:
Jörg Thalheim 2020-04-01 15:25:32 +01:00
parent ea7c07e783
commit 862b772839
No known key found for this signature in database
GPG key ID: 003F2096411B5F92
7 changed files with 112 additions and 0 deletions

39
tests/test.py Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python2
from tempfile import TemporaryDirectory
import os
import subprocess
from pathlib import Path
import shutil
import unittest
TEST_ROOT = Path(__file__).resolve().parent
class IntegrationTest(unittest.TestCase):
def setUp(self) -> None:
self.env = os.environ.copy()
self.dir = TemporaryDirectory()
self.env["HOME"] = str(self.dir.name)
self.testenv = Path(self.dir.name).joinpath("testenv")
shutil.copytree(TEST_ROOT.joinpath("testenv"), self.testenv)
direnvrc = str(TEST_ROOT.parent.joinpath("direnvrc"))
with open(self.testenv.joinpath(".envrc"), "w") as f:
f.write(f"source {direnvrc}\n")
f.write(f"use nix")
def test_direnv(self) -> None:
subprocess.run(
["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True
)
subprocess.run(
["direnv", "exec", str(self.testenv), "hello"], env=self.env, check=True
)
def tearDown(self) -> None:
self.dir.cleanup()
if __name__ == "__main__":
unittest.main()