Skip to content

Commit

Permalink
Add initial pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWLoupe committed Jul 26, 2024
1 parent 0baff50 commit 17c95af
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"test", "--capture=tee-sys"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
71 changes: 71 additions & 0 deletions test/test_lpm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import pytest
import os
import sys
from datetime import datetime
import re
import shutil

sys.path.insert(0, "./src")
import LPM


sys.path.insert(0, "./src/ASPython")
import ASTools

class TestLpmSrc:

def setup_method(self, method):
# Code to run before each test method

# create temporary folder
now = datetime.now()
timestamp = now.strftime("%y%m%d-%H-%M-%S")
test_folder = timestamp
self.test_dir = os.path.join("./temp/", test_folder)

# Source directory
asproject_template_source = "./test/asproject_template_librarybuilderproject"

# Copy the entire directory tree, allowing existing destination
shutil.copytree(asproject_template_source, self.test_dir, dirs_exist_ok=True)
print(f"Copied template to test folder: {self.test_dir}")

def teardown_method(self, method):
# Code to run after each test method

# shutil.rmtree(self.test_dir)
print("Teardown code")

def test_version(self, capsys, monkeypatch):

# argparse will exit from within for version, so we need the pytest context manager
with pytest.raises(SystemExit):
monkeypatch.setattr(sys, "argv", ["lpm.py", "-v"])
LPM.main()

# Verify output
captured = capsys.readouterr()
version_output = re.fullmatch(r"LPM: \d+\.\d+\.\d+\n", captured.out)
assert version_output is not None

def test_atn_install_as_src(self, monkeypatch):
monkeypatch.setattr(sys, "argv", ["lpm.py", "install", "atn", "-src"])
monkeypatch.chdir(self.test_dir)
LPM.main()

assert os.path.exists(os.path.join(".", "TempObjects", "sourceInfo.json"))

project = ASTools.Project(".")
build_result = project.build("Intel")
assert build_result.returncode == 0

monkeypatch.undo()

def test_build(self):
assert True






0 comments on commit 17c95af

Please sign in to comment.