Skip to content

Commit 78ba346

Browse files
committed
Initialized tests
1 parent a329574 commit 78ba346

3 files changed

Lines changed: 98 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
venv/
22
.idea/
33
__pycache__/
4+
.pytest_cache/
45
*.pyc
56

67
# Setuptools distribution folder.

test/test1.html renamed to test/input/test1.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ <h2> Forms ! </h2>
1616
<label for="someText"> Here is an input field </label>
1717
<input id="someText" type="text">
1818

19-
<div>
20-
<label> Option 1
21-
<input type="radio" name="my-radio">
22-
</label>
23-
<label> Option 2
24-
<input type="radio" name="my-radio">
25-
</label>
26-
<label> Option 3
27-
<input type="radio" name="my-radio">
28-
</label>
29-
</div>
19+
20+
<label> Option 1
21+
<input type="radio" name="my-radio">
22+
</label>
23+
<label> Option 2
24+
<input type="radio" name="my-radio">
25+
</label>
26+
<label> Option 3
27+
<input type="radio" name="my-radio">
28+
</label>
3029

3130
<button class="my-button-test" type="submit" onclick="alert('submitted')"> Click me</button>
3231
</form>

test/test_bootstrap.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import sys, os
2+
import copy
3+
import unittest
4+
import pytest
5+
from bs4 import BeautifulSoup
6+
7+
sys.path.insert(1, os.path.join(sys.path[0], '..'))
8+
from csskrt.bootstrapCsskrt import BootstrapCsskrt
9+
10+
11+
@pytest.fixture()
12+
def bootstrap_csskrt():
13+
bs_csskrt = BootstrapCsskrt(os.path.join(os.path.dirname(__file__), 'input/test1.html'))
14+
before = copy.copy(bs_csskrt.soup)
15+
bs_csskrt.freshify()
16+
after = bs_csskrt.soup
17+
return before, after
18+
19+
20+
class TestBootstrapButtons():
21+
def test_compare_num_button_tags(self, bootstrap_csskrt):
22+
before: BeautifulSoup = bootstrap_csskrt[0]
23+
after: BeautifulSoup = bootstrap_csskrt[1]
24+
tag = 'button'
25+
26+
old_tags = before.find_all(tag)
27+
new_tags = after.find_all(tag)
28+
assert (len(old_tags) == len(new_tags))
29+
30+
def test_buttons_styles(self, bootstrap_csskrt):
31+
before: BeautifulSoup = bootstrap_csskrt[0]
32+
after: BeautifulSoup = bootstrap_csskrt[1]
33+
tag = 'button'
34+
style = ['btn', 'btn-primary']
35+
36+
old_tags = before.find_all(tag)
37+
new_tags = after.find_all(tag)
38+
for old_t, new_t in zip(old_tags, new_tags):
39+
old_class = old_t.get('class', [])
40+
new_class = new_t.get('class', [])
41+
42+
if type(new_class) == str: # sometimes get returns str instead of list
43+
new_class = new_class.strip().split(' ')
44+
45+
assert(set(old_class).issubset(new_class))
46+
47+
def test_buttons_content(self, bootstrap_csskrt):
48+
before: BeautifulSoup = bootstrap_csskrt[0]
49+
after: BeautifulSoup = bootstrap_csskrt[1]
50+
tag = 'button'
51+
52+
old_tags = before.find_all(tag)
53+
new_tags = after.find_all(tag)
54+
for old_t, new_t in zip(old_tags, new_tags):
55+
assert old_t.get_text() == new_t.get_text()
56+
57+
58+
class TestBootstrapForm():
59+
def test_number_form_tags(self, bootstrap_csskrt):
60+
before: BeautifulSoup = bootstrap_csskrt[0]
61+
after: BeautifulSoup = bootstrap_csskrt[1]
62+
tag = 'form'
63+
64+
old_tags = before.find_all(tag)
65+
new_tags = after.find_all(tag)
66+
assert (len(old_tags) == len(new_tags))
67+
68+
69+
def test_form_wrapper(self, bootstrap_csskrt):
70+
before: BeautifulSoup = bootstrap_csskrt[0]
71+
after: BeautifulSoup = bootstrap_csskrt[1]
72+
tag = 'form'
73+
wrapper_class = 'form-group'
74+
75+
old_tags = before.find_all(tag)
76+
new_tags = after.find_all(tag)
77+
for form in new_tags:
78+
wrappers = form.find_all('div', recursive=False, attrs={'class': wrapper_class})
79+
inputs = form.find_all('input')
80+
assert len(wrappers) == len(inputs) # 1 input per wrapper ?
81+
82+
for wrapper in wrappers:
83+
inputs = wrapper.find_all('input')
84+
assert len(inputs) == 1
85+
86+
87+

0 commit comments

Comments
 (0)