* Added Gsetup.
Added Python tests for github actions.

* Add python requirments for pytests

#1238 

Co-authored-by: Scott Fennell <spfennell@gmail.com>
This commit is contained in:
cherpin00 2022-03-10 12:50:03 -06:00 committed by GitHub
parent 270fa52a54
commit b2c12b34fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 2277 additions and 3 deletions

View File

@ -13,7 +13,6 @@ on:
# Temporarily disable all tests for Issue #1188. # Temporarily disable all tests for Issue #1188.
branches-ignore: branches-ignore:
- '**' - '**'
jobs: jobs:
trick_32bit: trick_32bit:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
@ -77,6 +76,11 @@ jobs:
export MAKEFLAGS=-j`nproc` export MAKEFLAGS=-j`nproc`
./configure --without-hdf5 --enable-32bit ./configure --without-hdf5 --enable-32bit
make make
- name: Run Gsetup tests
run: |
. share/trick/pymods/trick/.venv/bin/activate
cd trick_source/trick_gsetup
./run_tests.py
- name: Run civet tests - name: Run civet tests
run: | run: |
cd share/trick/pymods/trick/ cd share/trick/pymods/trick/

View File

@ -13,7 +13,6 @@ on:
# Temporarily disable all tests for Issue #1188. # Temporarily disable all tests for Issue #1188.
branches-ignore: branches-ignore:
- '**' - '**'
jobs: jobs:
build: build:
strategy: strategy:
@ -184,6 +183,11 @@ jobs:
export MAKEFLAGS=-j`nproc` export MAKEFLAGS=-j`nproc`
./configure ./configure
make make
- name: Run Gsetup tests
run: |
. share/trick/pymods/trick/.venv/bin/activate
cd trick_source/trick_gsetup
./run_tests.py
- name: Run Civet Tests - name: Run Civet Tests
run: | run: |
cd share/trick/pymods/trick/ cd share/trick/pymods/trick/

View File

@ -13,7 +13,6 @@ on:
# Temporarily disable all tests for Issue #1188. # Temporarily disable all tests for Issue #1188.
branches-ignore: branches-ignore:
- '**' - '**'
jobs: jobs:
macOS: macOS:
runs-on: macos-latest runs-on: macos-latest
@ -50,6 +49,11 @@ jobs:
export MAKEFLAGS=-j4 export MAKEFLAGS=-j4
./configure ./configure
make make
- name: Run Gsetup tests
run: |
. share/trick/pymods/trick/.venv/bin/activate
cd trick_source/trick_gsetup
./run_tests.py
- name: Run Civet Tests - name: Run Civet Tests
run: | run: |
cd share/trick/pymods/trick/ cd share/trick/pymods/trick/

6
gsetup Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python3
import os
import sys
from trick_source.trick_gsetup.main import main
main(sys.argv[1:])

13
trick_source/trick_gsetup/.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
*__pycache__*
.vscode/*
config.log
config.status
share/trick/makefiles/config_user.mk
*.json
!tests/config_for_test_app_with_file.json
build/*
main
main.spec
*practice*
*.cache
help.txt

View File

@ -0,0 +1,18 @@
## Format for json config file
{
['name'] : 'Name of the application',
['landing'] : {
['version'] : 'version number',
['desc'] : 'description of this app'
},
'sections' : {
['section 1'] : {
'options' : {
['option 1'] : {
'type' : [<dir><bool><flag><envvar><radio><string>],
['desc'] : 'long description of the option'
['label'] : 'label for the option'
}
}
}
}

View File

@ -0,0 +1,376 @@
default_trick_config = {
"name": "Trick's Graphical Configuration",
"landing": {
"version": "1.0",
"desc": "This setup guide will allow you to easily see all the options that are available to configure Trick with."
},
"sections": {
"Configuration:": {
"options": {
"help" : {
"type" : "radio",
"options" : {"recursive" : {"desc" : "Display the short help of all the included packages and exit."}, "short" : {"desc" : "Display the short help and exit."}, "empty" : {"desc" : "Display the help and exit.", "label" :"regular"}}
},
"version": {
"desc": "display version information and exit",
"type": "flag",
"value": "no"
},
"quiet": {
"desc": "do not print `checking ...' messages",
"label" : "quite mode",
"type": "flag",
"value": "no"
},
"config-file" : {
"label" : "configuration cache file",
"desc" : "file to cache test results in",
"type" : "string"
},
"config-cache": {
"desc": "set the configuration cache file to 'config.cache'",
"type": "flag",
"value": "no"
},
"no-create": {
"desc": "do not create output files",
"type": "flag",
"value": "no"
},
"srcdir": {
"desc": "directory to find the sources in [configure dir or '..']",
"type": "dir",
"value": "",
"label": "source directory"
}
}
},
"Installation directories" : {
"options" : {
"prefix" : {
"type" : "string",
"desc" : "This is where we will install architecture-independent files. Default value is '/usr/local'."
},
"exec-prefix" : {
"type" : "string",
"desc" : "This is where we will install architecture-dependent files. Default value is set to [PREFIX].",
"label" : "executive prefix"
}
}
},
"Fine tuning of the installation directories:": {
"options": {
"bindir": {
"desc": "default is [executive prefix]/bin",
"type": "dir",
"value": "",
"label" : "user executables"
},
"sbindir": {
"desc": "default value is [executive prefix]/sbin",
"type": "dir",
"value": "",
"label": "system admin executables"
},
"libexecdir": {
"desc": "default value is [EPREFIX]/libexec",
"type": "dir",
"value": "",
"label":"program executables"
},
"sysconfdir": {
"desc": "default value is [PREFIX]/etc",
"type": "dir",
"value": "",
"label" : "read-only single-machine data"
},
"sharedstatedir": {
"desc": "default value is [PREFIX]/com",
"type": "dir",
"value": "",
"label" : "modifiable architecture-independent data"
},
"localstatedir": {
"desc": "default value is [PREFIX]/var",
"type": "dir",
"value": "",
"label": "modifiable single-machine data"
},
"libdir": {
"desc": "default value is [EPREFIX]/lib",
"type": "dir",
"value": "",
"label": "object code libraries"
},
"includedir": {
"desc": "default value is [PREFIX]/include",
"type": "dir",
"value": "",
"label" : "C header files"
},
"oldincludedir": {
"desc": "default value is [/usr/include]",
"type": "dir",
"value": "",
"label": "C header files for non-gcc"
},
"datarootdir": {
"desc": "default value is [PREFIX]/share",
"type": "dir",
"value": "",
"label":"read-only arch.-independent data root",
"hidden": True
},
"datadir": {
"desc": "default value is [PREFIX]/share",
"type": "dir",
"value": "",
"label" : "read-only architecture-independent data"
},
"infodir": {
"desc": "default value is [DATAROOTDIR]/info",
"type": "dir",
"value": "",
"label" : "info documentation"
},
"localedir": {
"desc": "default value is [DATAROOTDIR]/locale",
"type": "dir",
"value": "",
"label": "locale-dependent data"
},
"mandir": {
"desc": "default value is [DATAROOTDIR]/man",
"type": "dir",
"value": "",
"label": "man documentation"
},
"docdir": {
"desc": "default value is [DATAROOTDIR]/doc/trick",
"type": "dir",
"value": "",
"label": "documentation root"
},
"htmldir": {
"desc": "default value is [DOCDIR]",
"type": "dir",
"value": "",
"label": "html documentation"
},
"dvidir": {
"desc": "default value is [DOCDIR]",
"type": "dir",
"value": "",
"label": "dvi documentation"
},
"pdfdir": {
"desc": "default value is [DOCDIR]",
"type": "dir",
"value": "",
"label": "pdf documentation"
},
"psdir": {
"desc": "default value is [DOCDIR]",
"type": "dir",
"value": "",
"label": "ps documentation"
}
}
},
"X features:": {
"options": {
"x-includes": {
"desc": "where to put X include files",
"type": "dir",
"value": ""
},
"x-libraries": {
"desc": "where to put X library files",
"type": "dir",
"value": ""
}
}
},
"System types:": {
"options": {
"build" : {
"desc": "configure for building on ",
"hidden" : True,
"type" : "string"
},
"host": {
"desc" : "host to corss-compile for",
"label" : "corss compile host",
"type" : "string"
}
}
},
"Optional Features:": {
"options": {
"disable-option-checking": {
"desc": "--enable and --with options will be ignored if they are not recognized",
"type": "flag",
"value": "no",
"label" : "ignore unrecognized options. "
},
"32bit mode": {
"desc": "Force Trick and sims to compile 32bit",
"type": "flag",
},
"enable-offline": {
"desc": "Compile Trick in offline mode. Un-tar the trick's-offline directory in TRICK_HOME to use this feature",
"type": "flag",
"value": "no",
"label": "offline mode"
},
"disable-civet": {
"desc": "Compile Trick without webserver capabilities.",
"type": "flag",
"label" : "disable civet"
},
"disable-java": {
"desc": "disable the use java",
"type": "flag",
"label": "disable java"
},
"disable-er7utils": {
"desc": "disable the use of er7 utils",
"type": "flag",
"label": "disable er7utils"
},
}
},
"Optional Packages:": {
"options": {
"with-x": {
"desc": "",
"type": "flag",
"value": "no",
"label": "Use the X Window System"
},
"with-dmtcp": {
"desc": "",
"type": "dir",
"label": "DMTCP root directory"
},
"with-gsl": {
"desc": "",
"type": "dir",
"label": "GSL root directory"
},
"with-gtest": {
"desc": "",
"type": "dir",
"label": "GTEST root directory"
},
"with-hdf5": {
"type": "dir",
"label": "HDF5 root directory"
},
"with-llvm": {
"type": "dir",
"label": "LLVM root directory"
},
"with-python": {
"type": "dir",
"label": "python root directory"
},
"with-swig": {
"desc": "",
"type": "dir",
"label": "path of directory containing the SWIG executable."
},
"with-tpro": {
"desc": "",
"type": "dir",
"label": "TPRO root directory"
},
"with-udunits": {
"desc": "",
"type": "dir",
"label": "enable udunits"
},
"without-zlib": {
"desc": "check to disable zlib usage completely",
"type": "flag",
"value": "no",
"label": "disable zlib"
},
"with-zlib": {
"desc": "root directory path of zlib installation [defaults to /usr/local or /usr if not found in /usr/local]",
"type": "dir",
"label": "zlib directory"
},
"with-bc635": {
"desc": "",
"type": "dir",
"label": "BC635 root directory"
},
"with-prepend-path": {
"desc": "prepend this directory to path",
"type": "dir",
"label": "dir to prepend"
}
}
},
"Some influential environment variables:": {
"options": {
"CC": {
"desc": "C compiler command",
"type": "envvar",
"value": ""
},
"CFLAGS": {
"desc": "C compiler flags",
"type": "envvar",
"value": ""
},
"CPP": {
"desc": "C preprocessor",
"type": "envvar",
"value": ""
},
"CPPFLAGS": {
"desc": "(Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>",
"type": "envvar",
"value": ""
},
"CXX": {
"desc": "C++ compiler command",
"type": "envvar",
"value": ""
},
"CXXCPP": {
"desc": "C++ preprocessor",
"type": "envvar",
"value": ""
},
"CXXFLAGS": {
"desc": "C++ compiler flags",
"type": "envvar",
"value": ""
},
"JAVA_CC": {
"desc": "java compiler command",
"type": "envvar",
"value": ""
},
"JAVA_CC_FLAGS": {
"desc": "java compiler flags",
"type": "envvar",
"value": ""
},
"LDFLAGS": {
"desc": "linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir>",
"type": "envvar",
"value": ""
},
"LIBS": {
"desc": "libraries to pass to the linker, e.g. -l<library>",
"type": "envvar",
"value": ""
}
}
}
}
}

View File

@ -0,0 +1,59 @@
from os import EX_CANTCREAT
import json
from pprint import pprint
import os
def write_help(program):
os.system(f"{program} --help > help.txt")
def load():
with open("help.txt", "r") as f:
sections = {}
section = None
for line in f:
if line.endswith(":\n"):
section = line[:-1]
sections[section] = []
elif section is not None and line != "\n":
try:
argIndex = line.index("--") #TODO: Add env var
helpIndex = line.index(" ", argIndex)
sections[section].append((line[argIndex:helpIndex], line[helpIndex:].strip()))
except:
print("Invalid line:", line)
myJson = {
"sections" : {
}
}
for section in sections:
myJson["sections"][section] = {
"options" : {}
}
for t in sections[section]:
arg = t[0]
help = t[1]
try:
s = arg.split("=")
arg = s[0]
if "=" in arg:
continue
type = s[1]
if "DIR" in type:
type = "dir"
except:
type = "flag"
# print(arg, "=", type, ":", help)
if type in ("dir", "bool", "flag"):
if arg[-1] == "[":
arg = arg[:-1]
myJson["sections"][section]["options"][arg[2:]] = {
# "section": section,
"type": type,
"desc":help
}
else:
print("unuported type:", type)
with open("config.json", "w") as f:
f.write(json.dumps(myJson, indent=4))

1132
trick_source/trick_gsetup/main.py Executable file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
import pytest
import sys
import os
if __name__ == "__main__":
### CREATE VIRTUAL DISPLAY ###
os.system('Xvfb :1 -screen 0 1600x1200x16 &') # create virtual display with size 1600x1200 and 16 bit color. Color can be changed to 24 or 8
os.environ['DISPLAY']=':1.0' # tell X clients to use our virtual DISPLAY :1.0.
args = list(sys.argv[1:]) + ["tests"]
print("Runing tests with arguments:", args)
sys.exit(pytest.main(args))

View File

@ -0,0 +1 @@
import main

View File

@ -0,0 +1,15 @@
#! /home/cherpin/gsetup2/venv/bin/python3.8
#used for test cases
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--hello", help=f"print hello world.", action="store_true")
args = parser.parse_args()
if args.hello:
print("Hello World!")
else:
import os
print(os.environ.get("CC"))
print(os.environ.get("CFLAGS"))
print(os.environ.get("CPP"))
print(os.environ.get("CPPFLAGS"))

View File

@ -0,0 +1,33 @@
{
"sections" : {
"test_cases" : {
"size" : 12,
"options" : {
"option_name0" : {
"type" : "dir",
"value" : "/home/cherpin"
},
"option_name1" : {
"type" : "dir",
"value" : "/home/cherpin",
"width" : 20
},
"option_name2" : {
"type" : "dir",
"width" : 20
},
"option_name3" : {
"type" : "bool"
},
"option_name4" : {
"type" : "bool",
"value" : true
},
"option_name5" : {
"type" : "bool",
"value" : "yes"
}
}
}
}
}

View File

@ -0,0 +1,222 @@
import pytest
from main import App, LandingPage
from tkinter.constants import END
import os
def set_bool(bool, value):
bool.bool.set(value)
bool.handler()
return bool
def set_dir(dir, value):
dir.directory_entry.delete(0, END)
dir.directory_entry.insert(0, value)
dir.handler(None)
return dir
def test_search():
my_json = {
"sections" : {
"Test" : {
"options" : {
"help" : {
"type" : "flag"
},
"another" : {
"type" : "bool"
}
}
}
}
}
a = App(my_json)
result = a._search("help", a.sections)
expected = {
"sections" : {
"Test" : {
"options" : {
"help" : {
"type" : "flag"
}
}
}
}
}
a.get_frame().destroy()
assert expected == result
def test_app():
my_json = {
"sections" : {
"test_cases" : {
"size" : 12,
"options" : {
"option_name0" : {
"type" : "dir",
"value" : "/home/cherpin",
},
"option_name1" : {
"type" : "dir",
"value" : "/home/cherpin",
"width" : 20
},
"option_name2" : {
"type" : "dir",
"width" : 20
},
"option_name3" : {
"type" : "bool",
},
"option_name4" : {
"type" : "bool",
"value" : True
},
"option_name5" : {
"type" : "bool",
"value" : "yes"
}
}
},
}
}
a = App(my_json)
for key, value in a.sections.items():
for option, obj, in value.components.items():
if obj.type == "dir":
set_dir(obj, "hello")
elif obj.type == "bool":
set_bool(obj, True)
else:
raise RuntimeError("Unsupported type detected!")
my_json = {
"sections" : {
"test_cases" : {
"size" : 12,
"options" : {
"option_name0" : {
"type" : "dir",
"value" : "hello",
},
"option_name1" : {
"type" : "dir",
"value" : "hello",
"width" : 20
},
"option_name2" : {
"type" : "dir",
"width" : 20,
"value" : "hello"
},
"option_name3" : {
"type" : "bool",
"value" : "yes"
},
"option_name4" : {
"type" : "bool",
"value" : "yes"
},
"option_name5" : {
"type" : "bool",
"value" : "yes"
}
}
},
}
}
assert a.data._dict_() == my_json
a.get_frame().destroy()
def test_app_with_file():
dir_path = os.path.dirname(os.path.realpath(__file__))
a = App(f"{dir_path}/config_for_test_app_with_file.json")
for key, value in a.sections.items():
for option, obj, in value.components.items():
if obj.type == "dir":
set_dir(obj, "hello")
elif obj.type == "bool":
set_bool(obj, True)
else:
raise RuntimeError("Unsupported type detected!")
my_json = {
"sections" : {
"test_cases" : {
"size" : 12,
"options" : {
"option_name0" : {
"type" : "dir",
"value" : "hello",
},
"option_name1" : {
"type" : "dir",
"value" : "hello",
"width" : 20
},
"option_name2" : {
"type" : "dir",
"width" : 20,
"value" : "hello"
},
"option_name3" : {
"type" : "bool",
"value" : "yes"
},
"option_name4" : {
"type" : "bool",
"value" : "yes"
},
"option_name5" : {
"type" : "bool",
"value" : "yes"
}
}
},
}
}
assert a.data._dict_() == my_json
a.get_frame().destroy()
def test_unsupported_types():
my_json = {
"sections" : {
"test_cases" : {
"size" : 12,
"options" : {
"option_name0" : {
"type" : "dir",
"value" : "hello",
},
"option_name1" : {
"type" : "dir",
"value" : "hello",
"width" : 20
},
"option_name2" : {
"type" : "dir",
"width" : 20,
"value" : "hello"
},
"option_name3" : {
"type" : "bool",
"value" : "yes"
},
"option_name4" : {
"type" : "envvar",
"value" : "yes"
},
"option_name5" : {
"type" : "bad",
"value" : "yes"
}
}
},
}
}
with pytest.raises(RuntimeError) as e_info:
a = App(my_json)
e_info.value.args[0] == "Option type 'bad' in option_name5 is not implemented yet."
if __name__ == "__main__":
test_no_config()

View File

@ -0,0 +1,216 @@
import pytest
import os
from main import string_to_bool, bool_to_string, run, get_configure_command, Section, Data
def get_sections_from_json(my_json):
sections = {}
for section in my_json["sections"]:
sections[section] = Section(None, section, Data(**my_json))
return sections
def test_configure_flag_true():
program = "/home/cherpin/git/trick/configure"
expected = program + " --help"
my_json = {
"sections" : {
"test" : {
"options" : {
"help" : {
"value" : True,
"type" : "flag"
}
}
}
}
}
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "true"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "True"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "yes"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "YES"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
def test_configure_flag_false():
program = "/home/cherpin/git/trick/configure"
expected = program
my_json = {
"sections" : {
"test" : {
"options" : {
"help" : {
"value" : False,
"type" : "flag"
}
}
}
}
}
cmd = get_configure_command(program, get_sections_from_json(my_json))
print(cmd,"---",sep="")
print(expected,"---",sep="")
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "false"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "False"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "no"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "NO"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
def test_configure_bool():
program = "/home/cherpin/git/trick/configure"
expected = program + " --help='yes'"
my_json = {
"sections" : {
"test" : {
"options" : {
"help" : {
"value" : True,
"type" : "bool"
}
}
}
}
}
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "true"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "True"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "yes"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
my_json["sections"]["test"]["options"]["help"]["value"] = "YES"
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == expected
def test_configure_empty_string():
program = "/home/cherpin/git/trick/configure"
expected = program + " --help='yes'"
my_json = {
"sections" : {
"test" : {
"options" : {
"test_option" : {
"value" : "",
"type" : "dir"
}
}
}
}
}
cmd = get_configure_command(program, get_sections_from_json(my_json))
assert cmd == program
def test_string_to_bool():
test_cases_pass_fail_true = ("true", "True", "TRUE", "yes")
test_cases_pass_fail_false = ("false", "False", "FALSE", "no")
for test_case in test_cases_pass_fail_true:
assert string_to_bool(test_case) == True
for test_case in test_cases_pass_fail_false:
assert string_to_bool(test_case) == False
def test_bool_to_sting():
assert bool_to_string(True) == "yes"
assert bool_to_string(False) == "no"
def test_run():
dir_path = os.path.dirname(os.path.realpath(__file__))
stdout = run('echo Hello World!')
assert stdout == "Hello World!\n"
# stdout = run("./bad_file")
# assert stdout == "/bin/sh: 1: ./bad_file: not found\n"
stdout = run(f"python3 {dir_path}/check_env.py", "hello")
assert stdout == "Hello World!\n"
def test_envvar():
my_json = {
"sections" : {
"Test" : {
"options" : {
"help" : {
"type" : "flag",
"value" : "True"
},
"CC1" : {
"type" : "envvar",
"value" : ""
},
"CC2" : {
"type" : "envvar",
"value" : "hello"
},
"CC3" : {
"type" : "envvar",
"value" : "hello world"
}
}
}
}
}
cmd = get_configure_command("test", get_sections_from_json(my_json), include_vars=True)
assert os.environ.get("CC1") == None
assert os.environ.get("CC2") == "hello"
assert os.environ.get("CC3") == "hello world"
assert cmd == "CC2 = hello\nCC3 = hello world\ntest --help"
def test_unsupported_type():
my_json = {
"sections" : {
"Test" : {
"options" : {
"help" : {
"type" : "flag",
"value" : "True"
},
"CC1" : {
"type" : "envvar",
"value" : ""
},
"unsupported" : {
"type" : "bad",
"value" : ""
}
}
}
}
}
with pytest.raises(RuntimeError) as e_info:
cmd = get_configure_command("test", get_sections_from_json(my_json))
assert len(e_info.value.args[0]) > 0

View File

@ -0,0 +1,134 @@
import pytest
import os
import tkinter as tk
from tkinter.constants import END
from main import Data, OptionDir, OptionBool, Section, App
def set_bool(bool, value):
bool.bool.set(value)
bool.handler()
return bool
def set_dir(dir, value):
dir.directory_entry.delete(0, END)
dir.directory_entry.insert(0, value)
dir.handler(None)
return dir
def test_data():
name = "option 1"
obj = {
"type" : "dir",
"desc" : "test desc"
}
o = Data(**obj)
assert obj == o._dict_()
def test_dir_option():
json = {
"sections" : {
"section1" : {
"options" : {
"test1" : {
"type" : "dir"
}
}
}
}
}
test_phrase = "hello"
data = Data(**json)
root = tk.Tk()
o = OptionDir(root, "section1", "test1", data)
o.get_frame().pack()
set_dir(o, test_phrase)
json["sections"]["section1"]["options"]["test1"]["value"] = test_phrase
assert data._dict_() == json
def test_bool_option():
json = {
"sections" : {
"section1" : {
"options" : {
"bool_test_case" : {
"type" : "bool",
"value" : False
}
}
}
}
}
data = Data(**json)
root = tk.Tk()
o = OptionBool(root, "section1", "bool_test_case", data)
o.get_frame().pack()
set_bool(o, True)
json["sections"]["section1"]["options"]["bool_test_case"]["value"] = "yes"
assert data._dict_() == json
def test_section():
json = {
"sections" : {
"section1" : {
"options" : {
"bool_test_case" : {
"type" : "bool",
"value" : False
},
"dir_test_case1" : {
"type" : "dir"
},
"dir_test_case2" : {
"type" : "dir",
"value" : "/path/to/dir"
}
}
}
}
}
data = Data(**json)
root = tk.Tk()
o = Section(root, "section1", data)
o.get_frame().pack()
for c in o.components:
if o.components[c].type == "bool":
o.components[c].bool.set(True)
o.components[c].handler()
elif o.components[c].type == "dir":
o.components[c].directory_entry.delete(0, END)
o.components[c].directory_entry.insert(0, "hello")
o.components[c].handler(None)
else:
raise RuntimeError("Unsupported type detected!")
json = {
"sections" : {
"section1" : {
"options" : {
"bool_test_case" : {
"type" : "bool",
"value" : "yes"
},
"dir_test_case1" : {
"type" : "dir",
"value" : "hello"
},
"dir_test_case2" : {
"type" : "dir",
"value" : "hello"
}
}
}
}
}
assert data._dict_() == json

View File

@ -0,0 +1,16 @@
import pytest
from main import QuoteForPOSIX
def test_posix_quote():
q = QuoteForPOSIX("hello")
assert q == "'hello'"
q = QuoteForPOSIX("hello world")
assert q == "'hello world'"
q = QuoteForPOSIX("\n")
assert q == "'\n'"
q = QuoteForPOSIX("hello world $x")
assert q == "'hello world $x'"

View File

@ -0,0 +1,6 @@
import subprocess
def run(program):
print("Running:", program)
process = subprocess.run(program.split(" "), capture_output=True)
return process