Skip to content

Commit e916bd7

Browse files
committed
Gadgets/Stdrev: Reduce code duplication in tests
1 parent d476337 commit e916bd7

12 files changed

+245
-218
lines changed

gadgets/standard_revisions-tests/base.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,35 @@ def setUpClass(self):
4646
def tearDownClass(self):
4747
self.driver.quit()
4848

49+
def get_page(self, title):
50+
self.driver.get(self.base_url + "/w/" + title)
51+
52+
def select_standard(self, std):
53+
s = Select(self.driver.find_element_by_css_selector("select"))
54+
s.select_by_visible_text(std)
55+
56+
def select_diff(self):
57+
self.select_standard("C++98/03")
58+
59+
def select_cxx98(self):
60+
self.select_standard("C++98/03")
61+
62+
def select_cxx11(self):
63+
self.select_standard("C++11")
64+
65+
def select_cxx14(self):
66+
self.select_standard("C++14")
67+
68+
def select_cxx17(self):
69+
self.select_standard("C++17")
70+
71+
def select_cxx20(self):
72+
self.select_standard("C++20")
73+
74+
def assert_text_in_body(self, pattern):
75+
text = self.driver.find_element_by_xpath("//body").text
76+
self.assertIn(pattern, text)
77+
78+
def assert_text_not_in_body(self, pattern):
79+
text = self.driver.find_element_by_xpath("//body").text
80+
self.assertNotIn(pattern, text)

gadgets/standard_revisions-tests/hides-dcl-items-in-dcl-rev.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesDclItemsInDclRev(CppTestCase):
3030
def test_hides_dcl_items_in_dcl_rev(self):
31-
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dcl-items-in-dcl-rev")
33-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
34-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
35-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
36-
37-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
38-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
39-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
40-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
41-
42-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
43-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
44-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
45-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
31+
self.get_page("test-gadget-stdrev/hides-dcl-items-in-dcl-rev")
32+
self.assert_text_in_body("void always_visible")
33+
self.assert_text_in_body("void not_visible_in_cxx98")
34+
self.assert_text_in_body("void not_visible_in_cxx11")
35+
36+
self.select_cxx98()
37+
self.assert_text_in_body("void always_visible")
38+
self.assert_text_not_in_body("void not_visible_in_cxx98")
39+
self.assert_text_in_body("void not_visible_in_cxx11")
40+
41+
self.select_cxx11()
42+
self.assert_text_in_body("void always_visible")
43+
self.assert_text_in_body("void not_visible_in_cxx98")
44+
self.assert_text_not_in_body("void not_visible_in_cxx11")

gadgets/standard_revisions-tests/hides-dcl-items-in-member.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesDclItemsInMember(CppTestCase):
3030
def test_hides_dcl_items_in_member(self):
31-
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dcl-items-in-member")
33-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
34-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
35-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
36-
37-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
38-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
39-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
40-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
41-
42-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
43-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void always_visible[\s\S]*$")
44-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx98[\s\S]*$")
45-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
31+
self.get_page("test-gadget-stdrev/hides-dcl-items-in-member")
32+
self.assert_text_in_body("void always_visible")
33+
self.assert_text_in_body("void not_visible_in_cxx98")
34+
self.assert_text_in_body("void not_visible_in_cxx11")
35+
36+
self.select_cxx98()
37+
self.assert_text_in_body("void always_visible")
38+
self.assert_text_not_in_body("void not_visible_in_cxx98")
39+
self.assert_text_in_body("void not_visible_in_cxx11")
40+
41+
self.select_cxx11()
42+
self.assert_text_in_body("void always_visible")
43+
self.assert_text_in_body("void not_visible_in_cxx98")
44+
self.assert_text_not_in_body("void not_visible_in_cxx11")

gadgets/standard_revisions-tests/hides-dsc-items-with-explicit-mark.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesDscItemsWithExplicitMark(CppTestCase):
3030
def test_hides_dsc_items_with_explicit_mark(self):
31-
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dsc-items-with-explicit-mark")
33-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx98[\s\S]*$")
34-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx11[\s\S]*$")
35-
36-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
37-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx98[\s\S]*$")
38-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx11[\s\S]*$")
39-
40-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
41-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx98[\s\S]*$")
42-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx11[\s\S]*$")
31+
self.get_page("test-gadget-stdrev/hides-dsc-items-with-explicit-mark")
32+
self.assert_text_in_body("std::not_visible_in_cxx98")
33+
self.assert_text_in_body("std::not_visible_in_cxx11")
34+
35+
self.select_cxx98()
36+
self.assert_text_not_in_body("std::not_visible_in_cxx98")
37+
self.assert_text_in_body("std::not_visible_in_cxx11")
38+
39+
self.select_cxx11()
40+
self.assert_text_in_body("std::not_visible_in_cxx98")
41+
self.assert_text_not_in_body("std::not_visible_in_cxx11")
4342

gadgets/standard_revisions-tests/hides-h3-when-section-contains-dsc-with-removed-elems.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesH3WhenSectionContainsDscWithRemovedElems(CppTestCase):
3030

3131
def test_hides_h3_when_section_contains_dsc_with_removed_elems(self):
3232
driver = self.driver
33-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-elems")
33+
self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-elems")
3434
self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed())
3535

36-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
36+
self.select_cxx98()
3737
self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed())
3838

39-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
39+
self.select_cxx11()
4040
self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed())
4141

gadgets/standard_revisions-tests/hides-h3-when-section-contains-dsc-with-removed-until.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesH3WhenSectionContainsDscWithRemovedUntil(CppTestCase):
3030
def test_hides_h3_when_section_contains_dsc_with_removed_until(self):
3131
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-until")
32+
self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-until")
3333
self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed())
3434

35-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
35+
self.select_cxx98()
3636
self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed())
3737

38-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
38+
self.select_cxx11()
3939
self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed())

gadgets/standard_revisions-tests/hides-h3-when-section-contains-only-stdrev.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class HidesH3WhenSectionContainsOnlyStdrev(CppTestCase):
3030
def test_hides_h3_when_section_contains_only_stdrev(self):
3131
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-h3-when-section-contains-only-stdrev")
32+
self.get_page("test-gadget-stdrev/hides-h3-when-section-contains-only-stdrev")
3333
self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed())
3434

35-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
35+
self.select_cxx98()
3636
self.assertFalse(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed())
3737

38-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
38+
self.select_cxx11()
3939
self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed())
4040

gadgets/standard_revisions-tests/preserves-h3-when-section-visible.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class PreservesH3WhenSectionVisible(CppTestCase):
3030
def test_preserves_h3_when_section_visible(self):
3131
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
32+
self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
3333
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
3434

35-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
35+
self.select_cxx98()
3636
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
3737

38-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
38+
self.select_cxx11()
3939
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())

gadgets/standard_revisions-tests/preserves-h3-when-section-with-h5-visible.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class PreservesH3WhenSectionWithH5Visible(CppTestCase):
3030
def test_preserves_h3_when_section_with_h5_visible(self):
3131
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
32+
self.get_page("test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
3333
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
3434
self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed())
3535
self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed())
3636

37-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
37+
self.select_cxx98()
3838
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
3939
self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed())
4040
self.assertFalse(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed())
4141

42-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
42+
self.select_cxx11()
4343
self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
4444
self.assertTrue(driver.find_element_by_id("Should_always_be_visible2").is_displayed())
4545
self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed())

gadgets/standard_revisions-tests/rev-inl-works-in-text.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27-
from base import CppTestCase
27+
from base import *
2828

2929
class RevInlWorksInText(CppTestCase):
3030
def test_rev_inl_works_in_text(self):
31-
driver = self.driver
32-
driver.get(self.base_url + "/w/test-gadget-stdrev/rev-inl-works-in-text")
33-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx98[\s\S]*$")
34-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx11[\s\S]*$")
35-
36-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++98/03")
37-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx98[\s\S]*$")
38-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx11[\s\S]*$")
39-
40-
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
41-
self.assertRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx98[\s\S]*$")
42-
self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx11[\s\S]*$")
31+
self.get_page("test-gadget-stdrev/rev-inl-works-in-text")
32+
self.assert_text_in_body("not_visible_in_cxx98")
33+
self.assert_text_in_body("not_visible_in_cxx11")
34+
35+
self.select_cxx98()
36+
self.assert_text_not_in_body("not_visible_in_cxx98")
37+
self.assert_text_in_body("not_visible_in_cxx11")
38+
39+
self.select_cxx11()
40+
self.assert_text_in_body("not_visible_in_cxx98")
41+
self.assert_text_not_in_body("not_visible_in_cxx11")

0 commit comments

Comments
 (0)