|
| 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