uvllang 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uvllang-0.1.0/LICENSE +165 -0
- uvllang-0.1.0/PKG-INFO +127 -0
- uvllang-0.1.0/README.md +108 -0
- uvllang-0.1.0/pyproject.toml +40 -0
- uvllang-0.1.0/setup.cfg +4 -0
- uvllang-0.1.0/tests/test_uvl_parser.py +215 -0
- uvllang-0.1.0/uvllang/__init__.py +1 -0
- uvllang-0.1.0/uvllang/cli.py +70 -0
- uvllang-0.1.0/uvllang/main.py +316 -0
- uvllang-0.1.0/uvllang/uvl_custom_lexer.py +97 -0
- uvllang-0.1.0/uvllang/uvl_python_lexer.py +435 -0
- uvllang-0.1.0/uvllang/uvl_python_parser.py +3947 -0
- uvllang-0.1.0/uvllang/uvl_python_parser_listener.py +624 -0
- uvllang-0.1.0/uvllang.egg-info/PKG-INFO +127 -0
- uvllang-0.1.0/uvllang.egg-info/SOURCES.txt +17 -0
- uvllang-0.1.0/uvllang.egg-info/dependency_links.txt +1 -0
- uvllang-0.1.0/uvllang.egg-info/entry_points.txt +2 -0
- uvllang-0.1.0/uvllang.egg-info/requires.txt +7 -0
- uvllang-0.1.0/uvllang.egg-info/top_level.txt +1 -0
uvllang-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
uvllang-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uvllang
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parser for Universal Variability Language (UVL) with CNF conversion support
|
|
5
|
+
Author-email: UVL Team <jagalindo@us.es>
|
|
6
|
+
License-Expression: LGPL-3.0-or-later
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: antlr4-python3-runtime==4.13.1
|
|
13
|
+
Requires-Dist: sympy>=1.12
|
|
14
|
+
Requires-Dist: python-sat>=0.1.8.dev13
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
17
|
+
Requires-Dist: antlr4-tools>=0.2.0; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# uvllang
|
|
21
|
+
|
|
22
|
+
A Python parser for the Universal Variability Language (UVL). Based on ANTLR4, adopted from https://github.com/Universal-Variability-Language/uvl-parser.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install uvllang
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Parsing
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from uvllang.main import UVL
|
|
36
|
+
|
|
37
|
+
# Parse a UVL file
|
|
38
|
+
model = UVL(from_file="examples/automotive01.uvl")
|
|
39
|
+
|
|
40
|
+
# Access features
|
|
41
|
+
print(f"Number of features:", len(model.features))
|
|
42
|
+
|
|
43
|
+
# Access constraints
|
|
44
|
+
print("All constraints:", len(model.constraints))
|
|
45
|
+
print("Boolean constraints:", len(model.boolean_constraints))
|
|
46
|
+
print("Arithmetic constraints:", len(model.arithmetic_constraints))
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### CNF Conversion
|
|
50
|
+
|
|
51
|
+
Convert feature models to Conjunctive Normal Form (CNF) for SAT solvers:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from uvllang.main import UVL
|
|
55
|
+
|
|
56
|
+
# Parse UVL file
|
|
57
|
+
model = UVL(from_file="model.uvl")
|
|
58
|
+
|
|
59
|
+
# Convert to CNF (returns PySAT CNF object)
|
|
60
|
+
cnf = model.to_cnf()
|
|
61
|
+
cnf.to_file("output.dimacs")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Command Line Interface
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uvl2cnf --help
|
|
68
|
+
|
|
69
|
+
# Basic conversion
|
|
70
|
+
uvl2cnf model.uvl
|
|
71
|
+
|
|
72
|
+
# Specify output file
|
|
73
|
+
uvl2cnf model.uvl output.dimacs
|
|
74
|
+
|
|
75
|
+
# Verbose mode (lists ignored constraints)
|
|
76
|
+
uvl2cnf model.uvl -v
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Dependencies
|
|
80
|
+
|
|
81
|
+
- `antlr4-python3-runtime`: ANTLR4 parser runtime
|
|
82
|
+
- `sympy`: Symbolic mathematics for Boolean constraint processing
|
|
83
|
+
- `python-sat`: SAT solver library for CNF handling
|
|
84
|
+
|
|
85
|
+
## Testing
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Install development dependencies
|
|
89
|
+
pip install -e .
|
|
90
|
+
|
|
91
|
+
# Run tests
|
|
92
|
+
python -m pytest tests/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Generate parsers from grammar files
|
|
99
|
+
python generate_parsers.py
|
|
100
|
+
|
|
101
|
+
# Build package
|
|
102
|
+
python build_package.py
|
|
103
|
+
|
|
104
|
+
# Or build manually
|
|
105
|
+
python -m build
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Citation
|
|
109
|
+
|
|
110
|
+
If you use UVL in your research, please cite:
|
|
111
|
+
|
|
112
|
+
```bibtex
|
|
113
|
+
@article{UVL2024,
|
|
114
|
+
title = {UVL: Feature modelling with the Universal Variability Language},
|
|
115
|
+
journal = {Journal of Systems and Software},
|
|
116
|
+
volume = {225},
|
|
117
|
+
pages = {112326},
|
|
118
|
+
year = {2025},
|
|
119
|
+
doi = {https://doi.org/10.1016/j.jss.2024.112326},
|
|
120
|
+
author = {David Benavides and Chico Sundermann and Kevin Feichtinger and José A. Galindo and Rick Rabiser and Thomas Thüm}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Links
|
|
125
|
+
|
|
126
|
+
- [UVL Models Repository](https://github.com/Universal-Variability-Language/uvl-models)
|
|
127
|
+
- [UVL Website](https://universal-variability-language.github.io/)
|
uvllang-0.1.0/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# uvllang
|
|
2
|
+
|
|
3
|
+
A Python parser for the Universal Variability Language (UVL). Based on ANTLR4, adopted from https://github.com/Universal-Variability-Language/uvl-parser.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install uvllang
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Parsing
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from uvllang.main import UVL
|
|
17
|
+
|
|
18
|
+
# Parse a UVL file
|
|
19
|
+
model = UVL(from_file="examples/automotive01.uvl")
|
|
20
|
+
|
|
21
|
+
# Access features
|
|
22
|
+
print(f"Number of features:", len(model.features))
|
|
23
|
+
|
|
24
|
+
# Access constraints
|
|
25
|
+
print("All constraints:", len(model.constraints))
|
|
26
|
+
print("Boolean constraints:", len(model.boolean_constraints))
|
|
27
|
+
print("Arithmetic constraints:", len(model.arithmetic_constraints))
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### CNF Conversion
|
|
31
|
+
|
|
32
|
+
Convert feature models to Conjunctive Normal Form (CNF) for SAT solvers:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from uvllang.main import UVL
|
|
36
|
+
|
|
37
|
+
# Parse UVL file
|
|
38
|
+
model = UVL(from_file="model.uvl")
|
|
39
|
+
|
|
40
|
+
# Convert to CNF (returns PySAT CNF object)
|
|
41
|
+
cnf = model.to_cnf()
|
|
42
|
+
cnf.to_file("output.dimacs")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Command Line Interface
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uvl2cnf --help
|
|
49
|
+
|
|
50
|
+
# Basic conversion
|
|
51
|
+
uvl2cnf model.uvl
|
|
52
|
+
|
|
53
|
+
# Specify output file
|
|
54
|
+
uvl2cnf model.uvl output.dimacs
|
|
55
|
+
|
|
56
|
+
# Verbose mode (lists ignored constraints)
|
|
57
|
+
uvl2cnf model.uvl -v
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Dependencies
|
|
61
|
+
|
|
62
|
+
- `antlr4-python3-runtime`: ANTLR4 parser runtime
|
|
63
|
+
- `sympy`: Symbolic mathematics for Boolean constraint processing
|
|
64
|
+
- `python-sat`: SAT solver library for CNF handling
|
|
65
|
+
|
|
66
|
+
## Testing
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Install development dependencies
|
|
70
|
+
pip install -e .
|
|
71
|
+
|
|
72
|
+
# Run tests
|
|
73
|
+
python -m pytest tests/
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Generate parsers from grammar files
|
|
80
|
+
python generate_parsers.py
|
|
81
|
+
|
|
82
|
+
# Build package
|
|
83
|
+
python build_package.py
|
|
84
|
+
|
|
85
|
+
# Or build manually
|
|
86
|
+
python -m build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Citation
|
|
90
|
+
|
|
91
|
+
If you use UVL in your research, please cite:
|
|
92
|
+
|
|
93
|
+
```bibtex
|
|
94
|
+
@article{UVL2024,
|
|
95
|
+
title = {UVL: Feature modelling with the Universal Variability Language},
|
|
96
|
+
journal = {Journal of Systems and Software},
|
|
97
|
+
volume = {225},
|
|
98
|
+
pages = {112326},
|
|
99
|
+
year = {2025},
|
|
100
|
+
doi = {https://doi.org/10.1016/j.jss.2024.112326},
|
|
101
|
+
author = {David Benavides and Chico Sundermann and Kevin Feichtinger and José A. Galindo and Rick Rabiser and Thomas Thüm}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Links
|
|
106
|
+
|
|
107
|
+
- [UVL Models Repository](https://github.com/Universal-Variability-Language/uvl-models)
|
|
108
|
+
- [UVL Website](https://universal-variability-language.github.io/)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "uvllang"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Parser for Universal Variability Language (UVL) with CNF conversion support"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "LGPL-3.0-or-later"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "UVL Team", email = "jagalindo@us.es"},
|
|
13
|
+
]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.0"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"antlr4-python3-runtime==4.13.1",
|
|
21
|
+
"sympy>=1.12",
|
|
22
|
+
"python-sat>=0.1.8.dev13",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=7.0",
|
|
28
|
+
"antlr4-tools>=0.2.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
uvl2cnf = "uvllang.cli:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["."]
|
|
36
|
+
include = ["uvllang*"]
|
|
37
|
+
exclude = ["tests*", "examples*", "grammars*"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools]
|
|
40
|
+
py-modules = []
|
uvllang-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the UVL Parser package.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from uvllang.main import UVL
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestUVLParser:
|
|
12
|
+
"""Test cases for UVL parsing functionality."""
|
|
13
|
+
|
|
14
|
+
def test_parse_automotive01_uvl(self):
|
|
15
|
+
"""Test parsing the automotive01 UVL file."""
|
|
16
|
+
example_file = os.path.join(os.path.dirname(__file__), '..', 'examples', 'automotive01.uvl')
|
|
17
|
+
model = UVL(from_file=example_file)
|
|
18
|
+
|
|
19
|
+
assert model.tree is not None
|
|
20
|
+
assert len(model.features) == 2513
|
|
21
|
+
assert model.tree.getText().startswith('namespace')
|
|
22
|
+
|
|
23
|
+
def test_parse_eshop_uvl(self):
|
|
24
|
+
"""Test parsing the eshop UVL file."""
|
|
25
|
+
eshop_file = os.path.join(os.path.dirname(__file__), '..', 'examples', 'eshop.uvl')
|
|
26
|
+
model = UVL(from_file=eshop_file)
|
|
27
|
+
|
|
28
|
+
assert model.tree is not None
|
|
29
|
+
assert len(model.features) == 173
|
|
30
|
+
assert 'eShop' in model.features
|
|
31
|
+
|
|
32
|
+
def test_parse_simple_uvl(self):
|
|
33
|
+
"""Test parsing a simple UVL file."""
|
|
34
|
+
uvl_content = '''namespace TestNS
|
|
35
|
+
|
|
36
|
+
features
|
|
37
|
+
Root
|
|
38
|
+
mandatory
|
|
39
|
+
FeatureA
|
|
40
|
+
optional
|
|
41
|
+
FeatureB
|
|
42
|
+
'''
|
|
43
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
44
|
+
f.write(uvl_content)
|
|
45
|
+
temp_file = f.name
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
model = UVL(from_file=temp_file)
|
|
49
|
+
assert model.tree is not None
|
|
50
|
+
assert len(model.features) == 3
|
|
51
|
+
assert 'Root' in model.features
|
|
52
|
+
assert 'FeatureA' in model.features
|
|
53
|
+
assert 'FeatureB' in model.features
|
|
54
|
+
finally:
|
|
55
|
+
os.unlink(temp_file)
|
|
56
|
+
|
|
57
|
+
def test_invalid_file_raises_error(self):
|
|
58
|
+
"""Test that parsing an invalid file raises an error."""
|
|
59
|
+
invalid_content = 'This is not valid UVL syntax!'
|
|
60
|
+
|
|
61
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
|
|
62
|
+
f.write(invalid_content)
|
|
63
|
+
temp_file = f.name
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
with pytest.raises(Exception):
|
|
67
|
+
UVL(from_file=temp_file)
|
|
68
|
+
finally:
|
|
69
|
+
os.unlink(temp_file)
|
|
70
|
+
|
|
71
|
+
def test_nonexistent_file_raises_error(self):
|
|
72
|
+
"""Test that parsing a nonexistent file raises an error."""
|
|
73
|
+
with pytest.raises(FileNotFoundError):
|
|
74
|
+
UVL(from_file='nonexistent_file.uvl')
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class TestCNFConversion:
|
|
78
|
+
"""Test cases for CNF conversion functionality."""
|
|
79
|
+
|
|
80
|
+
def test_cnf_eshop(self):
|
|
81
|
+
"""Test CNF conversion for eshop.uvl."""
|
|
82
|
+
eshop_file = os.path.join(os.path.dirname(__file__), '..', 'examples', 'eshop.uvl')
|
|
83
|
+
model = UVL(from_file=eshop_file)
|
|
84
|
+
cnf = model.to_cnf()
|
|
85
|
+
|
|
86
|
+
assert len(cnf.clauses) == 289
|
|
87
|
+
assert cnf.nv == 173
|
|
88
|
+
assert all(isinstance(clause, list) for clause in cnf.clauses)
|
|
89
|
+
assert all(isinstance(lit, int) for clause in cnf.clauses for lit in clause)
|
|
90
|
+
|
|
91
|
+
def test_cnf_automotive01(self):
|
|
92
|
+
"""Test CNF conversion for automotive01.uvl."""
|
|
93
|
+
auto_file = os.path.join(os.path.dirname(__file__), '..', 'examples', 'automotive01.uvl')
|
|
94
|
+
model = UVL(from_file=auto_file)
|
|
95
|
+
cnf = model.to_cnf()
|
|
96
|
+
|
|
97
|
+
assert len(cnf.clauses) == 7876 # Updated: arithmetic constraints are now properly ignored
|
|
98
|
+
assert cnf.nv == 2513
|
|
99
|
+
assert all(isinstance(clause, list) for clause in cnf.clauses)
|
|
100
|
+
assert all(isinstance(lit, int) for clause in cnf.clauses for lit in clause)
|
|
101
|
+
|
|
102
|
+
def test_cnf_root_constraint(self):
|
|
103
|
+
"""Test that CNF includes root feature constraint."""
|
|
104
|
+
uvl_content = '''namespace Test
|
|
105
|
+
|
|
106
|
+
features
|
|
107
|
+
Root
|
|
108
|
+
mandatory
|
|
109
|
+
Child
|
|
110
|
+
'''
|
|
111
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
112
|
+
f.write(uvl_content)
|
|
113
|
+
temp_file = f.name
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
model = UVL(from_file=temp_file)
|
|
117
|
+
cnf = model.to_cnf()
|
|
118
|
+
|
|
119
|
+
assert [1] in cnf.clauses
|
|
120
|
+
finally:
|
|
121
|
+
os.unlink(temp_file)
|
|
122
|
+
|
|
123
|
+
def test_cnf_mandatory_constraint(self):
|
|
124
|
+
"""Test that CNF correctly encodes mandatory relationships."""
|
|
125
|
+
uvl_content = '''namespace Test
|
|
126
|
+
|
|
127
|
+
features
|
|
128
|
+
Root
|
|
129
|
+
mandatory
|
|
130
|
+
Child
|
|
131
|
+
'''
|
|
132
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
133
|
+
f.write(uvl_content)
|
|
134
|
+
temp_file = f.name
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
model = UVL(from_file=temp_file)
|
|
138
|
+
cnf = model.to_cnf()
|
|
139
|
+
|
|
140
|
+
assert [1] in cnf.clauses
|
|
141
|
+
assert [-1, 2] in cnf.clauses
|
|
142
|
+
assert [-2, 1] in cnf.clauses
|
|
143
|
+
finally:
|
|
144
|
+
os.unlink(temp_file)
|
|
145
|
+
|
|
146
|
+
def test_cnf_optional_constraint(self):
|
|
147
|
+
"""Test that CNF correctly encodes optional relationships."""
|
|
148
|
+
uvl_content = '''namespace Test
|
|
149
|
+
|
|
150
|
+
features
|
|
151
|
+
Root
|
|
152
|
+
optional
|
|
153
|
+
OptionalChild
|
|
154
|
+
'''
|
|
155
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
156
|
+
f.write(uvl_content)
|
|
157
|
+
temp_file = f.name
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
model = UVL(from_file=temp_file)
|
|
161
|
+
cnf = model.to_cnf()
|
|
162
|
+
|
|
163
|
+
assert [1] in cnf.clauses
|
|
164
|
+
assert [-2, 1] in cnf.clauses
|
|
165
|
+
assert [-1, 2] not in cnf.clauses
|
|
166
|
+
finally:
|
|
167
|
+
os.unlink(temp_file)
|
|
168
|
+
|
|
169
|
+
def test_cnf_xor_constraint(self):
|
|
170
|
+
"""Test that CNF correctly encodes XOR/alternative groups."""
|
|
171
|
+
uvl_content = '''namespace Test
|
|
172
|
+
|
|
173
|
+
features
|
|
174
|
+
Root
|
|
175
|
+
alternative
|
|
176
|
+
ChildA
|
|
177
|
+
ChildB
|
|
178
|
+
'''
|
|
179
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
180
|
+
f.write(uvl_content)
|
|
181
|
+
temp_file = f.name
|
|
182
|
+
|
|
183
|
+
try:
|
|
184
|
+
model = UVL(from_file=temp_file)
|
|
185
|
+
cnf = model.to_cnf()
|
|
186
|
+
|
|
187
|
+
assert [1] in cnf.clauses
|
|
188
|
+
assert [-1, 2, 3] in cnf.clauses
|
|
189
|
+
assert [-2, -3] in cnf.clauses
|
|
190
|
+
finally:
|
|
191
|
+
os.unlink(temp_file)
|
|
192
|
+
|
|
193
|
+
def test_cnf_or_constraint(self):
|
|
194
|
+
"""Test that CNF correctly encodes OR groups."""
|
|
195
|
+
uvl_content = '''namespace Test
|
|
196
|
+
|
|
197
|
+
features
|
|
198
|
+
Root
|
|
199
|
+
or
|
|
200
|
+
ChildA
|
|
201
|
+
ChildB
|
|
202
|
+
'''
|
|
203
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.uvl', delete=False) as f:
|
|
204
|
+
f.write(uvl_content)
|
|
205
|
+
temp_file = f.name
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
model = UVL(from_file=temp_file)
|
|
209
|
+
cnf = model.to_cnf()
|
|
210
|
+
|
|
211
|
+
assert [1] in cnf.clauses
|
|
212
|
+
assert [-1, 2, 3] in cnf.clauses
|
|
213
|
+
assert [-2, -3] not in cnf.clauses
|
|
214
|
+
finally:
|
|
215
|
+
os.unlink(temp_file)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import UVL
|