<commit_before>import unittest
import six
import rdflib
from mock import patch, Mock

from grlc.fileLoaders import LocalLoader
from grlc import gquery

from flask import Flask


class TestGQuery(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.loader = LocalLoader('./tests/repo/')
        self.app = Flask('unittests')

    def test_guess_endpoint(self):
        with self.app.test_request_context('/?endpoint=http://url-endpoint/from-url/sparql'):
            endpoint, _ = gquery.guess_endpoint_uri('', self.loader)
            self.assertIn('from-url', endpoint,
                          'Should match endpoint given in url')

        with self.app.test_request_context('/'):
            endpoint, _ = gquery.guess_endpoint_uri('', self.loader)
            self.assertIn('from-file', endpoint,
                          'Should match endpoint in endpoint.txt')

            rq, _ = self.loader.getTextForName('test-rq')
            endpoint, _ = gquery.guess_endpoint_uri(rq, self.loader)
            self.assertIn('from-decorator', endpoint,
                          'Should match endpoint in test-rq.rq')

    def test_get_parameters(self):
        rq, _ = self.loader.getTextForName('test-rq')

        params = gquery.get_parameters(rq, '', '', {})
        for paramName, param in params.iteritems():
            self.assertIn('name', param, 'Should have a name')
            self.assertIn('type', param, 'Should have a type')
            self.assertIn('required', param, 'Should have a required')

            orig = param['original']
            if '_iri' in orig:
                self.assertEqual(param['type'], 'iri', 'Should be type iri')
            if '_number' in orig:
                self.assertEqual(param['type'], 'number',
                                 'Should be type number')
            if '_literal' in orig:
                self.assertEqual(param['type'], 'literal',
                                 'Should be type literal')
            if '_en' in orig:
                self.assertEqual(param['type'], 'literal',
                                 'Should be type literal')
                self.assertEqual(param['lang'], 'en', 'Should be en language')
            if '_integer' in orig:
                self.assertEqual(
                    param['datatype'], 'xsd:integer', 'Should be type xsd:integer')
            if '_xsd_date' in orig:
                self.assertEqual(param['datatype'],
                                 'xsd:date', 'Should be type xsd:date')<commit_msg>update type string format iri<commit_after>import unittest
import six
import rdflib
from mock import patch, Mock

from grlc.fileLoaders import LocalLoader
from grlc import gquery

from flask import Flask


class TestGQuery(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.loader = LocalLoader('./tests/repo/')
        self.app = Flask('unittests')

    def test_guess_endpoint(self):
        with self.app.test_request_context('/?endpoint=http://url-endpoint/from-url/sparql'):
            endpoint, _ = gquery.guess_endpoint_uri('', self.loader)
            self.assertIn('from-url', endpoint,
                          'Should match endpoint given in url')

        with self.app.test_request_context('/'):
            endpoint, _ = gquery.guess_endpoint_uri('', self.loader)
            self.assertIn('from-file', endpoint,
                          'Should match endpoint in endpoint.txt')

            rq, _ = self.loader.getTextForName('test-rq')
            endpoint, _ = gquery.guess_endpoint_uri(rq, self.loader)
            self.assertIn('from-decorator', endpoint,
                          'Should match endpoint in test-rq.rq')

    def test_get_parameters(self):
        rq, _ = self.loader.getTextForName('test-rq')

        params = gquery.get_parameters(rq, '', '', {})
        for paramName, param in params.iteritems():
            self.assertIn('name', param, 'Should have a name')
            self.assertIn('type', param, 'Should have a type')
            self.assertIn('required', param, 'Should have a required')

            orig = param['original']
            if '_iri' in orig:
                self.assertEqual(param['type'], 'string', 'Should be type string')
                self.assertEqual(param['format'], 'iri', 'Should be format iri')
            if '_number' in orig:
                self.assertEqual(param['type'], 'number',
                                 'Should be type number')
            if '_literal' in orig:
                self.assertEqual(param['type'], 'literal',
                                 'Should be type literal')
            if '_en' in orig:
                self.assertEqual(param['type'], 'literal',
                                 'Should be type literal')
                self.assertEqual(param['lang'], 'en', 'Should be en language')
            if '_integer' in orig:
                self.assertEqual(
                    param['datatype'], 'xsd:integer', 'Should be type xsd:integer')
            if '_xsd_date' in orig:
                self.assertEqual(param['datatype'],
                                 'xsd:date', 'Should be type xsd:date')
{'fraction_non_alphanumeric': 0.11811328049487725, 'fraction_numerical': 0.0, 'mean_word_length': 1.9397727272727272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1265288', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1328, 'n_words': 347}