| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import pytest |
| 19 |
|
| 20 |
from selenium.webdriver.common.print_page_options import PrintOptions |
| 21 |
|
| 22 |
|
| 23 |
@pytest.fixture |
| 24 |
def print_options(): |
| 25 |
return PrintOptions() |
| 26 |
|
| 27 |
|
| 28 |
def test_set_orientation(print_options): |
| 29 |
print_options.orientation = "portrait" |
| 30 |
assert print_options.orientation == "portrait" |
| 31 |
|
| 32 |
|
| 33 |
def test_raises_exception_if_orientation_is_invalid(print_options): |
| 34 |
with pytest.raises(ValueError): |
| 35 |
print_options.orientation = "foobar" |
| 36 |
|
| 37 |
|
| 38 |
def test_set_scale(print_options): |
| 39 |
print_options.scale = 1 |
| 40 |
assert print_options.scale == 1 |
| 41 |
|
| 42 |
|
| 43 |
def test_raises_exception_if_scale_is_outside_range(print_options): |
| 44 |
with pytest.raises(ValueError): |
| 45 |
print_options.scale = 3 |
| 46 |
|
| 47 |
|
| 48 |
def test_raises_exception_if_scale_is_not_an_integer(print_options): |
| 49 |
with pytest.raises(ValueError): |
| 50 |
print_options.scale = "1" |
| 51 |
|
| 52 |
|
| 53 |
def test_set_background(print_options): |
| 54 |
print_options.background = True |
| 55 |
assert print_options.background is True |
| 56 |
|
| 57 |
|
| 58 |
def test_unset_value_to_be_none(print_options): |
| 59 |
assert print_options.page_width is None |
| 60 |
|
| 61 |
|
| 62 |
def test_set_width(print_options): |
| 63 |
print_options.page_width = 3 |
| 64 |
assert print_options.page_width == 3 |
| 65 |
|
| 66 |
|
| 67 |
def test_raises_exception_if_set_invalid_width(print_options): |
| 68 |
with pytest.raises(ValueError): |
| 69 |
print_options.page_width = -1 |
| 70 |
|
| 71 |
|
| 72 |
def test_raises_exception_if_set_with_not_int(print_options): |
| 73 |
with pytest.raises(ValueError): |
| 74 |
print_options.page_width = "2" |
| 75 |
|
| 76 |
|
| 77 |
def test_set_height(print_options): |
| 78 |
print_options.page_height = 2 |
| 79 |
assert print_options.page_height == 2 |
| 80 |
|
| 81 |
|
| 82 |
def test_set_shrink_to_fit(print_options): |
| 83 |
print_options.shrink_to_fit = True |
| 84 |
assert print_options.shrink_to_fit is True |
| 85 |
|
| 86 |
|
| 87 |
def test_raises_exception_if_set_shrink_to_fit_non_bool(print_options): |
| 88 |
with pytest.raises(ValueError): |
| 89 |
print_options.shrink_to_fit = "True" |
| 90 |
|
| 91 |
|
| 92 |
def test_set_page_ranges(print_options): |
| 93 |
print_options.page_ranges = ["1-2"] |
| 94 |
assert print_options.page_ranges == ["1-2"] |
| 95 |
|
| 96 |
|
| 97 |
def test_raises_exception_if_page_ranges_not_list(print_options): |
| 98 |
with pytest.raises(ValueError): |
| 99 |
print_options.page_ranges = "foobar" |
| 100 |
|
| 101 |
|
| 102 |
def test_margin_height(print_options): |
| 103 |
print_options.margin_top = 2 |
| 104 |
assert print_options.margin_top == 2 |
| 105 |
|
| 106 |
|
| 107 |
def test_raises_exception_if_margin_is_invalid(print_options): |
| 108 |
with pytest.raises(ValueError): |
| 109 |
print_options.margin_top = -1 |
| 110 |
|
| 111 |
with pytest.raises(ValueError): |
| 112 |
print_options.margin_top = "2" |