Skip to content

Commit 925b18c

Browse files
committed
Add the test suite
This adds a Pytest application for testing the `csspring` package and suggests `mypy` as type checker as part of testing. Keep in mind that the test suite targets the _installed_ `csspring` package.
1 parent e1bae87 commit 925b18c

36 files changed

Lines changed: 2991 additions & 0 deletions

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ Another factor for choosing Python was the fact we couldn't find any _sufficient
8787

8888
Ignoring the "css" part, "spring" in the name refers to my starting the project in [early] spring of [2024]. A Python package needs a name, _some_ name, from the get-go, and the name stuck. I pronounce it as *cs-spring*.
8989

90+
## Testing & Development
91+
92+
The project defines a form of testing of the library, utilizing [Mypy](http://mypy-lang.org) and [Pytest](http://pytest.org). Testing is encapsulated with the `tests` directory and relies on a set of optional project dependencies specified with the `pyproject.toml` file and installed with e.g. `pip`, below with repository directory as current working directory (CWD):
93+
94+
```shell
95+
pip install .[tests]
96+
```
97+
98+
The above will set up current Python environment for running of the tests by installing all packages supplemental to `csspring` (which is the subject of testing). Since the environment should pertain to specifically testing of `csspring`, it is advised to allocate a _dedicated_ environment for the procedure, using e.g. the "virtualenv" framework. At any rate, `pip` may rightfully warn you if there's no such current environment.
99+
100+
With the testing environment set up, testing may be executed with the repository as current working directory:
101+
102+
```shell
103+
mypy
104+
pytest
105+
```
106+
107+
The first command performs static type checking, verifying so-called _type soundness_ of all of the code. The second command verifies the parser as it performs when invoked. Each is independent of the other and may be invoked in either order. Each is expected to return zero exit code to signify required passing of all tests. The commands should be executed for each snapshot of the contents of the repository before committing said snapshot, to maintain confidence in the library expressed through the test suite and to protect against regressions.
108+
109+
> [!NOTE]
110+
> The test suite is not written to uncover e.g. breaking API changes —— tests may pass even if the library no longer conforms to an API of a specific version. For instance, testing of the parser currently merely checks whether all of input is consumed, which does not preclude the possibility of the _structure_ of the parse tree having changed in a manner which would constitute breaking changes in the API. Put another way: what tests there currently are, these were written towards checking the soundness of the CSS parsing behaviour and its conformance to the specification(s), not necessarily whether the [correct] results it vends, conform to a specific interfaces as expected by the developer. Implicitly, however, since testing of behaviour uses the interfaces, minimal soundness of these must be implied.
111+
90112
## References
91113

92114
[^1]: http://github.com/w3c/csswg-drafts/issues/10119#issuecomment-2016156566

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ license = { file = "LICENSE.txt" }
2323
readme = "README.md"
2424
requires-python = ">=3.11"
2525

26+
[project.optional-dependencies]
27+
tests = [ "mypy>=1.7.0", "pytest>=6.2.4" ]
28+
2629
[project.urls]
2730
Github = "http://github.com/amn/csspring"
2831

32+
[tool.mypy]
33+
packages = [ "csspring" ]
34+
35+
[tool.pytest.ini_options]
36+
testpaths = "tests"
37+
2938
[tool.setuptools_scm]

tests/1c8a182edf42bae99ae3bfb5303eb27f-product.py

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
2+
@font-face{
3+
font-family: "Lilita";
4+
src: url(LilitaOne-Regular.ttf);
5+
6+
}
7+
:any-link {
8+
color: var(--accent-color);
9+
}
10+
html {
11+
--accent-color: rgb(31, 35, 39);
12+
--background-color: hsl(0, 0%, 90%);
13+
--background-color: rgb(212, 212, 222);
14+
--text-color: black;
15+
--alternative-text-color: pink;/*white;*/
16+
background: var(--background-color);
17+
color: var(--text-color);
18+
letter-spacing: .05em;
19+
20+
}
21+
body {
22+
text-align: center;
23+
font-family: "Lilita";
24+
margin: 0;
25+
}
26+
button, input {
27+
all: initial;
28+
padding: 0.25em 0.5em;
29+
font: inherit;
30+
}
31+
32+
h1, h2, h3, h4, h5, h6 {
33+
text-transform: uppercase;
34+
color: white;
35+
}
36+
37+
h1{
38+
font-size: 1.2em;
39+
}
40+
41+
h3{
42+
font-size: 1em;
43+
}
44+
45+
img, iframe {
46+
max-width: 100%;
47+
}
48+
49+
img {
50+
height: auto;
51+
}
52+
53+
54+
@keyframes float {
55+
0% {
56+
transform: translatey(0px);
57+
}
58+
50% {
59+
transform: translatey(+15px);
60+
}
61+
100% {
62+
transform: translatey(0px);
63+
}
64+
}
65+
66+
.logo {
67+
display: block;
68+
margin: auto;
69+
border-radius: 50%;
70+
height: auto;
71+
margin: auto;
72+
overflow: hidden;
73+
animation: float 6s ease-in-out infinite;
74+
img { width: 100%; height: auto; }
75+
}
76+
77+
.banner, .screenshot {
78+
width: 100%;
79+
}
80+
81+
82+
input:not([type]), input[type=text], input[type=email] {
83+
font-size: 2em;
84+
background: var(--alternative-text-color);
85+
color: var(--text-color);
86+
font-family: arial;
87+
font-size: 1.2em;
88+
}
89+
90+
input[type=button], input[type=submit], button {
91+
margin: 0.75em 0em 0.75em 0em;
92+
font-size: 2em;
93+
/*background: var(--text-color);*/
94+
95+
color: white;
96+
cursor: pointer;
97+
background: rgb(227, 118, 149);
98+
}
99+
100+
#mce-EMAIL
101+
{
102+
max-width: 100%;
103+
box-sizing: border-box;
104+
background: white;
105+
106+
}
107+
body > header{
108+
background-image: url(dark_cover.jpg);
109+
padding: 1em;
110+
background-size: cover;
111+
}
112+
.games-gallery {
113+
display: flex;
114+
justify-content: safe center;
115+
flex-wrap: wrap;
116+
gap: 2em;
117+
margin: 2em;
118+
119+
}
120+
.games {
121+
text-align: center;
122+
text-transform: uppercase;
123+
124+
}
125+
.games > a:first-child > img {
126+
width: 17em;
127+
/*border-radius: 50%;*/
128+
}
129+
130+
131+
body > .story > img.screenshot {
132+
object-fit: cover;
133+
max-width: 100%;
134+
height: auto;
135+
}
136+
137+
138+
139+
#steam-widget {
140+
height: 12em;
141+
width: 75%;
142+
border: none;
143+
}
144+
145+
body > article {
146+
margin-block: 1em;
147+
}
148+
149+
150+
#mc_embed_signup {
151+
background: var(--accent-color);
152+
color: var(--alternative-text-color);
153+
margin: auto;
154+
padding: 0.25em 1em;
155+
width: 100%;
156+
box-sizing: border-box;
157+
}
158+
#title-text {
159+
margin-block-end: 0;
160+
margin-block-start: 2em;
161+
}
162+
163+
164+
/*#mc-embedded-subscribe-form input {
165+
max-width: 100%;
166+
box-sizing: border-box;
167+
}
168+
#mc-embedded-subscribe-form .note small {
169+
all: unset;
170+
}
171+
#mc-embedded-subscribe-form [name="b_8dc478765ff45bcd403eacd19_cabdbec384"] {
172+
display: none;
173+
}*/
174+
#social-media-buttons-paragraph > a {
175+
display: inline-block;
176+
text-align: center;
177+
}
178+
#social-media-buttons-paragraph > a:before {
179+
background-position: center;
180+
background-size: contain;
181+
background-repeat: no-repeat;
182+
content: '';
183+
display: block;
184+
width: 4em;
185+
height: 4em;
186+
}
187+
#social-media-buttons-paragraph > a.twitter:before {
188+
background-image: url(twitter.png);
189+
}
190+
#social-media-buttons-paragraph > a.facebook:before {
191+
background-image: url(facebook.png);
192+
}
193+
#social-media-buttons-paragraph > a.instagram:before {
194+
background-image: url(instagram.png);
195+
}
196+
#social-media-buttons-paragraph > a.email:before {
197+
background-image: url(email.png);
198+
}
199+
#social-media-buttons-paragraph > a.discord:before {
200+
background-image: url(discord.png);
201+
}
202+
#copyright{
203+
font-size: .65em;
204+
}

tests/34cb4a2de40eaef671522833c0cecd76-product.py

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)