Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/devel/orphaned_tests.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file orphaned_tests.py
15
# @author Jakob Erdmann
16
# @date 2024-02-21
17
18
19
"""find test folders that are not mentioned in the respective test suite
20
"""
21
from __future__ import print_function
22
import sys
23
import os
24
from collections import defaultdict
25
if 'SUMO_HOME' in os.environ:
26
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
27
import sumolib # noqa
28
29
30
def get_options():
31
op = sumolib.options.ArgumentParser()
32
op.add_argument("root", category="input", type=op.file,
33
help="root directory of tests to analyze")
34
op.add_argument("--variant", action="store_true", default=False,
35
help="check whether the test is orphaned in the given suite variant")
36
op.add_argument("--fix", action="store_true", default=False,
37
help="automatically append missing tests to test suites")
38
return op.parse_args()
39
40
41
options = get_options()
42
numFixed = 0
43
44
for root, dirs, files in os.walk(options.root):
45
numSuites = 0
46
known_variant_tests = defaultdict(lambda: set())
47
suites = []
48
for fname in files:
49
if fname.startswith("testsuite."):
50
suites.append(fname)
51
with open(os.path.join(root, fname)) as s:
52
for line in s:
53
line = line.strip()
54
if line and not line.startswith("#"):
55
known_variant_tests[fname].add(line)
56
if suites:
57
orphaned = []
58
mainSuite = sorted(suites)[0]
59
if options.variant:
60
mainSuite = options.variant
61
known_tests = known_variant_tests[mainSuite]
62
for d in dirs:
63
if d in ["filter_files", "data"]:
64
continue
65
if d not in known_tests:
66
orphaned.append(d)
67
print("orphaned '%s'" % os.path.join(root, d))
68
if orphaned and options.fix:
69
numFixed += len(orphaned)
70
# suite with shortest name is the main one
71
with open(os.path.join(root, mainSuite), "a") as s:
72
for t in orphaned:
73
print("\n", file=s)
74
print(t, file=s)
75
76
if options.fix:
77
print("fixed %s orphaned tests" % numFixed)
78
79