Skip to content

Commit c42e22f

Browse files
committed
Add more tests, fix test config paths
1 parent 110f42b commit c42e22f

File tree

5 files changed

+124
-9
lines changed

5 files changed

+124
-9
lines changed

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from livvkit import __main__
2+
import pytest
3+
from pathlib import Path
4+
5+
6+
@pytest.fixture(scope="session")
7+
def generate_livv_output():
8+
outdir = "simple_extn_output"
9+
__main__.main(["-V", "tests/simple_test.yml", "-o", outdir])
10+
return Path(outdir, "index.json")

tests/extension_simple.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright (c) 2015-2025, UT-BATTELLE, LLC
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
30+
"""
31+
This template provides an example of a minimal LIVVkit extension.
32+
"""
33+
34+
from livvkit import elements as el
35+
# Don't remove summarize_result...this is used by livvkit.components.validation
36+
# to have the summaries appear on the main LIVVkit output page
37+
from lex.common import summarize_result as sum_common
38+
39+
def run(name, config):
40+
"""
41+
Runs the extension.
42+
43+
Args:
44+
name: The name of the extension
45+
config: A dictionary representation of the configuration file
46+
47+
Returns:
48+
A LIVVkit page element containing the LIVVkit elements to display on a webpage
49+
"""
50+
# TODO: Put your analysis here
51+
element_list = [
52+
el.Error("Unimplemented test", "This test contains no analysis code!"),
53+
el.Table(
54+
title="Sample Table",
55+
data={"row1": [1, 2, 3], "row2": [4, 5, 6]},
56+
transpose=True,
57+
),
58+
]
59+
60+
return el.Page(
61+
name,
62+
config["description"],
63+
elements=element_list,
64+
)
65+
66+
67+
def print_summary(summary):
68+
"""
69+
Print out a summary generated by this module's summarize_result method
70+
"""
71+
raise NotImplementedError
72+
73+
74+
def summarize_result(result):
75+
"""
76+
Provides a snapshot of the extension's results to be provided on the
77+
summary webpage and printed to STDOUT via the print_summary method
78+
"""
79+
return sum_common(result)
80+
81+
def populate_metadata():
82+
"""
83+
Generates the metadata needed for the output summary page
84+
"""
85+
raise NotImplementedError

tests/simple_test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
ExtensionTest:
3+
module: tests/extension_simple.py
4+
description: A minimal LIVVkit extensions test.

tests/test_convert.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66

77
def test_convert_to_yaml():
8-
in_file = "json_to_convert.json"
9-
out_file = "yml_to_convert.yml"
10-
ref_file = "yml_reference.yml"
8+
in_file = Path("tests", "json_to_convert.json")
9+
out_file = Path("tests", "yml_to_convert.yml")
10+
ref_file = Path("tests", "yml_reference.yml")
1111

12-
assert not Path(out_file).exists()
13-
lconvert.json_to_yaml(Path(in_file))
14-
assert Path(out_file).exists()
15-
ref_yml = fcn.read_yaml(Path(ref_file))
16-
test_yml = fcn.read_yaml(Path(out_file))
12+
assert not out_file.exists()
13+
lconvert.json_to_yaml(in_file)
14+
assert out_file.exists()
15+
ref_yml = fcn.read_yaml(ref_file)
16+
test_yml = fcn.read_yaml(out_file)
1717
assert ref_yml == test_yml
1818
os.remove(out_file)
19-
assert not Path(out_file).exists()
19+
assert not out_file.exists()

tests/test_simple.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from livvkit import __main__
2+
from pathlib import Path
3+
import json
4+
5+
6+
def test_simple_extn(generate_livv_output):
7+
with open(generate_livv_output, "r") as _fin:
8+
test_data = json.loads(_fin.read())
9+
10+
assert "Page" in test_data, "LIVVkit Page not found in extn output"
11+
test_fields = ['elements', 'title', 'description', '_ref_list', 'Data', '__module__', '_html_template', '_latex_template']
12+
for _field in test_fields:
13+
assert _field in test_data["Page"], f"{_field} not found in Page data"
14+
15+
assert len(test_data["Page"]["elements"][0]["Table"]["data"]) > 0, "NOT ENOUGH ELEMENTS FOR NAV TO BE GENERATED"
16+
assert test_data["Page"]["elements"][0]["Table"]["title"] == "Validation", "TABLE TITLE INCORRECT"

0 commit comments

Comments
 (0)