|
| 1 | +# Copyright (c) 2020, Moritz E. Beber. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +"""Test that the paper size enum behaves as expected.""" |
| 17 | + |
| 18 | +from collections import namedtuple |
| 19 | + |
| 20 | +import pytest |
| 21 | + |
| 22 | +from structurizr.view import Orientation, PaperSize |
| 23 | + |
| 24 | + |
| 25 | +Dimensions = namedtuple("Dimensions", "value, size, orientation, width, height") |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture( |
| 29 | + scope="module", |
| 30 | + params=[ |
| 31 | + ("A6_Portrait", "A6", Orientation.Portrait, 1240, 1748), |
| 32 | + ("A6_Landscape", "A6", Orientation.Landscape, 1748, 1240), |
| 33 | + ("A5_Portrait", "A5", Orientation.Portrait, 1748, 2480), |
| 34 | + ("A5_Landscape", "A5", Orientation.Landscape, 2480, 1748), |
| 35 | + ("A4_Portrait", "A4", Orientation.Portrait, 2480, 3508), |
| 36 | + ("A4_Landscape", "A4", Orientation.Landscape, 3508, 2480), |
| 37 | + ("A3_Portrait", "A3", Orientation.Portrait, 3508, 4961), |
| 38 | + ("A3_Landscape", "A3", Orientation.Landscape, 4961, 3508), |
| 39 | + ("A2_Portrait", "A2", Orientation.Portrait, 4961, 7016), |
| 40 | + ("A2_Landscape", "A2", Orientation.Landscape, 7016, 4961), |
| 41 | + ("A1_Portrait", "A1", Orientation.Portrait, 7016, 9933), |
| 42 | + ("A1_Landscape", "A1", Orientation.Landscape, 9933, 7016), |
| 43 | + ("A0_Portrait", "A0", Orientation.Portrait, 9933, 14043), |
| 44 | + ("A0_Landscape", "A0", Orientation.Landscape, 14043, 9933), |
| 45 | + ("Letter_Portrait", "Letter", Orientation.Portrait, 2550, 3300), |
| 46 | + ("Letter_Landscape", "Letter", Orientation.Landscape, 3300, 2550), |
| 47 | + ("Legal_Portrait", "Legal", Orientation.Portrait, 2550, 4200), |
| 48 | + ("Legal_Landscape", "Legal", Orientation.Landscape, 4200, 2550), |
| 49 | + ("Slide_4_3", "Slide 4:3", Orientation.Landscape, 3306, 2480), |
| 50 | + ("Slide_16_9", "Slide 16:9", Orientation.Landscape, 3508, 1973), |
| 51 | + ("Slide_16_10", "Slide 16:10", Orientation.Landscape, 3508, 2193), |
| 52 | + ], |
| 53 | + ids=[ |
| 54 | + "A6_Portrait", |
| 55 | + "A6_Landscape", |
| 56 | + "A5_Portrait", |
| 57 | + "A5_Landscape", |
| 58 | + "A4_Portrait", |
| 59 | + "A4_Landscape", |
| 60 | + "A3_Portrait", |
| 61 | + "A3_Landscape", |
| 62 | + "A2_Portrait", |
| 63 | + "A2_Landscape", |
| 64 | + "A1_Portrait", |
| 65 | + "A1_Landscape", |
| 66 | + "A0_Portrait", |
| 67 | + "A0_Landscape", |
| 68 | + "Letter_Portrait", |
| 69 | + "Letter_Landscape", |
| 70 | + "Legal_Portrait", |
| 71 | + "Legal_Landscape", |
| 72 | + "Slide_4_3", |
| 73 | + "Slide_16_9", |
| 74 | + "Slide_16_10", |
| 75 | + ], |
| 76 | +) |
| 77 | +def expected(request): |
| 78 | + return Dimensions(*request.param) |
| 79 | + |
| 80 | + |
| 81 | +def test_from_value(expected: Dimensions): |
| 82 | + paper = PaperSize(expected.value) |
| 83 | + assert paper.name == expected.value |
| 84 | + assert paper.value == expected.value |
| 85 | + assert paper.size == expected.size |
| 86 | + assert paper.orientation == expected.orientation |
| 87 | + assert paper.width == expected.width |
| 88 | + assert paper.height == expected.height |
| 89 | + |
| 90 | + |
| 91 | +def test_from_getitem(expected: Dimensions): |
| 92 | + paper = PaperSize[expected.value] |
| 93 | + assert paper.name == expected.value |
| 94 | + assert paper.value == expected.value |
| 95 | + assert paper.size == expected.size |
| 96 | + assert paper.orientation == expected.orientation |
| 97 | + assert paper.width == expected.width |
| 98 | + assert paper.height == expected.height |
| 99 | + |
| 100 | + |
| 101 | +def test_from_attribute(expected: Dimensions): |
| 102 | + paper = getattr(PaperSize, expected.value) |
| 103 | + assert paper.name == expected.value |
| 104 | + assert paper.value == expected.value |
| 105 | + assert paper.size == expected.size |
| 106 | + assert paper.orientation == expected.orientation |
| 107 | + assert paper.width == expected.width |
| 108 | + assert paper.height == expected.height |
0 commit comments