File: test_cmd.py

package info (click to toggle)
glvis 4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,780 kB
  • sloc: cpp: 35,217; ansic: 5,695; sh: 340; makefile: 301; python: 193
file content (84 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files
# LICENSE and NOTICE for details. LLNL-CODE-443271.
#
# This file is part of the GLVis visualization tool and library. For more
# information and source code availability see https://glvis.org.
#
# GLVis is free software; you can redistribute it and/or modify it under the
# terms of the BSD-3 license. We welcome feedback and contributions, see file
# CONTRIBUTING.md for details.

"""
Code snippets to test glvis in the command-line. None of the code
contained here is currently being used.
"""

# Globals
screenshot_keys = "Sq"
screenshot_file = "GLVis_s01.png"

# Below are key commands that are passed to the -keys command-line argument for
# glvis in order to perform testing on raw mesh/grid function data (i.e. non-
# streams).
test_cases = {
    "magnify": "*****",
    "axes1": "a",
    "axes2": "aa",
    "mesh1": "m",
    "mesh2": "mm",
    "cut_plane": "i",
    "cut_plane_rotate": "iyyyy",
    "cut_plane_rotate_back": "iyyyyYYYY",
    "cut_plane_transl": "izzzz",
    "cut_plane_transl_back": "izzzzZZZZ",
    "orient2d_1": "R",
    "orient2d_2": "RR",
    "orient2d_3": "RRR",
    "orient2d_4": "RRRR",
    "orient2d_5": "RRRRR",
    "orient2d_6": "RRRRRR",
    "orient3d": "Rr",
    "perspective": "j",
}

# Function to test a given glvis command with a variety of key-based commands.
def test_case(exec_path, exec_args, baseline, t_group, t_name, cmd):
    print(f"Testing {t_group}:{t_name}...")
    full_screenshot_cmd = cmd + screenshot_keys
    cmd = f"{exec_path} {exec_args} -k \"{full_screenshot_cmd}\""
    print(f"Exec: {cmd}")
    ret = os.system(cmd + " > /dev/null 2>&1")
    if ret != 0:
        print(f"[FAIL] GLVis exited with error code {ret}.")
        return False
    if not os.path.exists(t_group):
        os.mkdir(t_group)
    output_name = f"{t_group}/{t_name}.png"

    ret = os.system(f"mv {screenshot_file} {output_name}")
    if ret != 0:
        print(f"[FAIL] Could not move output image: exit code {ret}.")
        return False

    if baseline:
        baseline_name = f"{baseline}/test.{t_name}.png"
        return compare_images(baseline_name, output_name)
    else:
        print("[IGNORE] No baseline exists to compare against.")
        return True

def test_cmd(exec_path, exec_args, tgroup, baseline):
    try:
        os.remove(screenshot_file)
    except OSError:
        pass
    all_tests_passed = True
    for testname, cmds in test_cases.items():
        result = test_case(exec_path, exec_args, baseline, tgroup, testname, cmds)
        all_tests_passed = all_tests_passed and result

    if all_tests_passed:
        print("All tests passed.")
    else:
        sys.exit(1)