Skip to content

Commit 3125237

Browse files
committed
Wrote basic tests for bulma and bootstrap
1 parent 78ba346 commit 3125237

3 files changed

Lines changed: 92 additions & 11 deletions

File tree

test/input/test1.html

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

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>
19+
<label for="opt1"> Option 1 </label>
20+
<input type="radio" id="opt1" name="my-radio">
21+
<label for="opt2"> Option 2 </label>
22+
<input type="radio" id="opt2" name="my-radio">
23+
<label for="opt3"> Option 3 </label>
24+
<input type="radio" id="opt3" name="my-radio">
2925

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

test/test_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def bootstrap_csskrt():
1616
after = bs_csskrt.soup
1717
return before, after
1818

19+
# Fix checkbox case
1920

2021
class TestBootstrapButtons():
2122
def test_compare_num_button_tags(self, bootstrap_csskrt):
@@ -65,7 +66,6 @@ def test_number_form_tags(self, bootstrap_csskrt):
6566
new_tags = after.find_all(tag)
6667
assert (len(old_tags) == len(new_tags))
6768

68-
6969
def test_form_wrapper(self, bootstrap_csskrt):
7070
before: BeautifulSoup = bootstrap_csskrt[0]
7171
after: BeautifulSoup = bootstrap_csskrt[1]

test/test_bulma.py

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

0 commit comments

Comments
 (0)