コード例 #1
0
    def test_mm_and_formatting(self, ppmm):
        # Integer and float support
        assert css_dimension_to_mm("123mm", ppmm) == 123
        assert css_dimension_to_mm("1.23mm", ppmm) == 1.23

        # With optional plus
        assert css_dimension_to_mm("+1mm", ppmm) == 1

        # With whitespace
        assert css_dimension_to_mm(" 1 mm ", ppmm) == 1
        assert css_dimension_to_mm(" + 1 mm ", ppmm) == 1
コード例 #2
0
    def test_unsupported_units(self, ppmm):
        # No font-relative sizes
        with pytest.raises(ValueError):
            css_dimension_to_mm("1em", ppmm)

        # No viewport-relative sizes
        with pytest.raises(ValueError):
            css_dimension_to_mm("1vw", ppmm)
        with pytest.raises(ValueError):
            css_dimension_to_mm("1%", ppmm)
コード例 #3
0
 def test_malformed(self, value, ppmm):
     with pytest.raises(ValueError):
         css_dimension_to_mm(value, ppmm)
コード例 #4
0
 def test_negative(self, ppmm):
     with pytest.raises(ValueError):
         css_dimension_to_mm("-1mm", ppmm)
コード例 #5
0
    def test_pixels(self, ppmm):
        assert css_dimension_to_mm("1px", ppmm) == 1.0 / ppmm
        assert css_dimension_to_mm("1", ppmm) == 1.0 / ppmm

        assert css_dimension_to_mm("2px", ppmm) == 2.0 / ppmm
        assert css_dimension_to_mm("2", ppmm) == 2.0 / ppmm
コード例 #6
0
 def test_point(self, ppmm):
     assert css_dimension_to_mm("72pt", ppmm) == \
         css_dimension_to_mm("1in", ppmm)
コード例 #7
0
 def test_pica(self, ppmm):
     assert css_dimension_to_mm("6pc", ppmm) == \
         css_dimension_to_mm("1in", ppmm)
コード例 #8
0
 def test_inches(self, ppmm):
     assert css_dimension_to_mm("1in", ppmm) == 25.4
     assert css_dimension_to_mm("2in", ppmm) == 50.8
コード例 #9
0
 def test_Q(self, ppmm):
     assert css_dimension_to_mm("1Q", ppmm) == 0.25
     assert css_dimension_to_mm("4Q", ppmm) == 1.0
コード例 #10
0
 def test_cm(self, ppmm):
     assert css_dimension_to_mm("1.2cm", ppmm) == 12.0