Skip to content

Commit

Permalink
Merge pull request #4 from aucampia/iwana-20211217T0021-add_tests
Browse files Browse the repository at this point in the history
Added additional tests for Literal language tag.
  • Loading branch information
veyndan committed Dec 17, 2021
2 parents ce1f3f8 + 7596b49 commit 42cbf96
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions test/test_literal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from decimal import Decimal
from typing import Any, Optional, Type
import unittest
import datetime

import rdflib # needed for eval(repr(...)) below
from rdflib.term import Literal, URIRef, _XSD_DOUBLE, bind, _XSD_BOOLEAN
from rdflib.namespace import XSD

import pytest


class TestLiteral(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -42,17 +45,41 @@ def test_literal_from_bool(self):
self.assertEqual(l.datatype, rdflib.XSD["boolean"])


class TestNewPT:
# NOTE: TestNewPT is written for pytest so that pytest features like
# parametrize can be used.
# New tests should be added here instead of in TestNew.
@pytest.mark.parametrize(
"lang, exception_type",
[
({}, TypeError),
([], TypeError),
(1, TypeError),
(b"en", TypeError),
("999", ValueError),
("-", ValueError),
],
)
def test_cant_pass_invalid_lang(
self,
lang: Any,
exception_type: Type[Exception],
):
"""
Construction of Literal fails if the language tag is invalid.
"""
with pytest.raises(exception_type):
Literal("foo", lang=lang)


class TestNew(unittest.TestCase):
# NOTE: Please use TestNewPT for new tests instead of this which is written
# for unittest.
def testCantPassLangAndDatatype(self):
self.assertRaises(
TypeError, Literal, "foo", lang="en", datatype=URIRef("http://example.com/")
)

def testCantPassInvalidLang(self):
self.assertRaises(
ValueError, Literal, "foo", lang="999"
)

def testFromOtherLiteral(self):
l = Literal(1)
l2 = Literal(l)
Expand Down

0 comments on commit 42cbf96

Please sign in to comment.