mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 07:02:18 +00:00
Add flatc python tests to CI (#7437)
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -29,6 +29,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
chmod +x flatc
|
chmod +x flatc
|
||||||
./flatc --version
|
./flatc --version
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--flatc",
|
"--flatc", help="path of the Flat C compiler relative to the root directory"
|
||||||
help="path of the Flat C compiler relative to the root directory")
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Get the path where this script is located so we can invoke the script from
|
# Get the path where this script is located so we can invoke the script from
|
||||||
@@ -52,30 +52,47 @@ assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
|||||||
|
|
||||||
# Execute the flatc compiler with the specified parameters
|
# Execute the flatc compiler with the specified parameters
|
||||||
def flatc(options, cwd=script_path):
|
def flatc(options, cwd=script_path):
|
||||||
cmd = [str(flatc_path)] + options
|
cmd = [str(flatc_path)] + options
|
||||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||||
|
|
||||||
|
|
||||||
def make_absolute(filename, path=script_path):
|
def make_absolute(filename, path=script_path):
|
||||||
return Path(path, filename).absolute()
|
return Path(path, filename).absolute()
|
||||||
|
|
||||||
|
|
||||||
def assert_file_exists(filename, path=script_path):
|
def assert_file_exists(filename, path=script_path):
|
||||||
file = Path(path, filename)
|
file = Path(path, filename)
|
||||||
assert file.exists(), "could not find file: " + filename
|
assert file.exists(), "could not find file: " + filename
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
||||||
def assert_file_contains(file, needle):
|
def assert_file_contains(file, needle):
|
||||||
assert needle in open(file).read(), "coudn't find '"+needle+"' in file: "+str(file)
|
assert needle in open(file).read(), (
|
||||||
|
"coudn't find '" + needle + "' in file: " + str(file)
|
||||||
|
)
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
||||||
def assert_file_and_contents(file, needle, path=script_path):
|
def assert_file_and_contents(file, needle, path=script_path):
|
||||||
assert_file_contains(assert_file_exists(file, path), needle).unlink()
|
assert_file_contains(assert_file_exists(file, path), needle).unlink()
|
||||||
|
|
||||||
|
|
||||||
def run_all(module):
|
def run_all(module):
|
||||||
methods = [func for func in dir(module) if callable(getattr(module, func)) and not func.startswith("__")]
|
methods = [
|
||||||
for method in methods:
|
func
|
||||||
try:
|
for func in dir(module)
|
||||||
print(method)
|
if callable(getattr(module, func)) and not func.startswith("__")
|
||||||
getattr(module, method)(module)
|
]
|
||||||
print(" [PASSED]")
|
failing = 0
|
||||||
except Exception as e:
|
passing = 0
|
||||||
print(" [FAILED]: " +str(e))
|
for method in methods:
|
||||||
|
try:
|
||||||
|
print(method)
|
||||||
|
getattr(module, method)(module)
|
||||||
|
print(" [PASSED]")
|
||||||
|
passing = passing + 1
|
||||||
|
except Exception as e:
|
||||||
|
print(" [FAILED]: " + str(e))
|
||||||
|
failing = failing + 1
|
||||||
|
print("{0}: {1} of {2} passsed".format(module.__name__, passing, passing + failing))
|
||||||
|
return passing, failing
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys;
|
||||||
|
|
||||||
from flatc_test import run_all
|
from flatc_test import run_all
|
||||||
from flatc_cpp_tests import CppTests
|
from flatc_cpp_tests import CppTests
|
||||||
|
|
||||||
run_all(CppTests)
|
passing, failing = run_all(CppTests)
|
||||||
|
|
||||||
|
if failing > 0:
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user