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
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)
def test_malformed(self, value, ppmm): with pytest.raises(ValueError): css_dimension_to_mm(value, ppmm)
def test_negative(self, ppmm): with pytest.raises(ValueError): css_dimension_to_mm("-1mm", ppmm)
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
def test_point(self, ppmm): assert css_dimension_to_mm("72pt", ppmm) == \ css_dimension_to_mm("1in", ppmm)
def test_pica(self, ppmm): assert css_dimension_to_mm("6pc", ppmm) == \ css_dimension_to_mm("1in", ppmm)
def test_inches(self, ppmm): assert css_dimension_to_mm("1in", ppmm) == 25.4 assert css_dimension_to_mm("2in", ppmm) == 50.8
def test_Q(self, ppmm): assert css_dimension_to_mm("1Q", ppmm) == 0.25 assert css_dimension_to_mm("4Q", ppmm) == 1.0
def test_cm(self, ppmm): assert css_dimension_to_mm("1.2cm", ppmm) == 12.0