<commit_before>from django.test import TestCase

from tmapi.constants import XSD_ANY_URI, XSD_INT, XSD_STRING
from tmapi.models import TopicMapSystem


class DatatypeAwareAbstractTestCase (TestCase):

    def get_datatype_aware (self):
        raise NotImplementedError
    
    def setUp (self):
        self.tms = TopicMapSystem()
        self.tm = self.tms.create_topic_map('http://www.example.org/tm/')
        self._xsd_any_uri = self.tms.create_locator(XSD_ANY_URI)
        self._xsd_int = self.tms.create_locator(XSD_INT)
        self._xsd_string = self.tms.create_locator(XSD_STRING)

    def test_string (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        value = 'a string'
        dt.set_value(value)
        self.assertEqual(value, dt.get_value())
        self.assertEqual(self._xsd_string, dt.get_datatype())

    def test_string_explicit (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        value = 'a string'
        dt.set_value(value, self._xsd_string)
        self.assertEqual(value, dt.get_value())
        self.assertEqual(self._xsd_string, dt.get_datatype())

    def test_uri (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        iri = 'http://www.example.org/'
        value = self.tm.create_locator(iri)
        dt.set_value(value)
        self.assertEqual(iri, dt.get_value())
        self.assertEqual(self._xsd_any_uri, dt.get_datatype())
        self.assertEqual(value, dt.locator_value())

    def test_uri_explicit (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        iri = 'http://www.example.org/'
        value = self.tm.create_locator(iri)
        dt.set_value(iri, self._xsd_any_uri)
        self.assertEqual(iri, dt.get_value())
        self.assertEqual(self._xsd_any_uri, dt.get_datatype())
        self.assertEqual(value, dt.locator_value())

    def test_user_datatype (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        datatype = self.tm.create_locator('http://www.example.org/datatype')
        value = 'Value'
        dt.set_value(value, datatype)
        self.assertEqual(datatype, dt.get_datatype())
        self.assertEqual(value, dt.get_value())<commit_msg>Added more of the datatype tests.<commit_after>from django.test import TestCase

from tmapi.exceptions import ModelConstraintException
from tmapi.models import TopicMapSystem


class DatatypeAwareAbstractTestCase (TestCase):

    _XSD = 'http://www.w3.org/2001/XMLSchema#'
    _XSD_ANY_URI = _XSD + 'anyURI'
    _XSD_INT = _XSD + 'int'
    _XSD_STRING = _XSD + 'string'
    
    def get_datatype_aware (self):
        raise NotImplementedError
    
    def setUp (self):
        self.tms = TopicMapSystem()
        self.tm = self.tms.create_topic_map('http://www.example.org/tm/')
        self._xsd_any_uri = self.tms.create_locator(self._XSD_ANY_URI)
        self._xsd_int = self.tms.create_locator(self._XSD_INT)
        self._xsd_string = self.tms.create_locator(self._XSD_STRING)

    def test_string (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        value = 'a string'
        dt.set_value(value)
        self.assertEqual(value, dt.get_value())
        self.assertEqual(self._xsd_string, dt.get_datatype())

    def test_string_explicit (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        value = 'a string'
        dt.set_value(value, self._xsd_string)
        self.assertEqual(value, dt.get_value())
        self.assertEqual(self._xsd_string, dt.get_datatype())

    def test_uri (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        iri = 'http://www.example.org/'
        value = self.tm.create_locator(iri)
        dt.set_value(value)
        self.assertEqual(iri, dt.get_value())
        self.assertEqual(self._xsd_any_uri, dt.get_datatype())
        self.assertEqual(value, dt.locator_value())

    def test_uri_explicit (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        iri = 'http://www.example.org/'
        value = self.tm.create_locator(iri)
        dt.set_value(iri, self._xsd_any_uri)
        self.assertEqual(iri, dt.get_value())
        self.assertEqual(self._xsd_any_uri, dt.get_datatype())
        self.assertEqual(value, dt.locator_value())

    def test_user_datatype (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        datatype = self.tm.create_locator('http://www.example.org/datatype')
        value = 'Value'
        dt.set_value(value, datatype)
        self.assertEqual(datatype, dt.get_datatype())
        self.assertEqual(value, dt.get_value())

    def test_illegal_datatype (self):
        # This test is not applicable in Python.
        pass

    def test_illegal_string_value (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        self.assertRaises(ModelConstraintException, dt.set_value, None)

    def test_illegal_string_value_explicit (self):
        try:
            dt = self.get_datatype_aware()
        except NotImplementedError:
            return
        self.assertRaises(ModelConstraintException, dt.set_value, None,
                          self._xsd_string)
{'fraction_non_alphanumeric': 0.1004534356470178, 'fraction_numerical': 0.0008719916288803627, 'mean_word_length': 2.3874778499704665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 9, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4734852', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1769, 'n_words': 309}