<commit_before>import inspect
import os
import random
import rdflib
import re
import subprocess
import sys
import unittest

rdflib.plugin.register('nifttl', rdflib.serializer.Serializer, 'pyontutils.ttlser', 'CustomTurtleSerializer')

class TestTtlser(unittest.TestCase):
    def setUp(self):

        goodpath = 'test/good.ttl'
        self.badpath = 'test/nasty.ttl'
        actualpath = 'test/actual.ttl'
        self.actualpath2 = 'test/actual2.ttl'

        print(self.make_ser())

        with open(goodpath, 'rb') as f:
            self.good = f.read()

        self.actual = self.serialize()
        with open(actualpath, 'wb') as f:
            f.write(self.actual)
        

    def test_ser(self):
        assert self.actual == self.good

    def serialize(self):
        graph = rdflib.Graph()
        graph.parse(self.badpath, format='turtle')
        #actual = graph.serialize(format='nifttl')
        actual = graph.serialize(format='turtle')  # no change when the file is identical
        return actual

    def make_ser(self):
        header = ('import rdflib\n'
                  'import sys\n'
                  "rdflib.plugin.register('nifttl', rdflib.serializer.Serializer, 'pyontutils.ttlser', 'CustomTurtleSerializer')\n"
                  'class Thing:\n'
                  '    badpath = \'%s\'\n') % self.badpath
        src = inspect.getsource(self.serialize)
        after =  't = Thing()\nsys.stdout.buffer.write(t.serialize())\n'
        return header + src + after


    def test_deterministic(self):
        nofail = True
        env = os.environ.copy()
        seed = None  # 'random'
        for _ in range(10):
            if seed is not None:
                env['PYTHONHASHSEED'] = str(seed)
            else:
                env.pop('PYTHONHASHSEED', None)
            cmd_line = [sys.executable, '-c', self.make_ser()]
            p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,<commit_msg>test ttlser switched to actually test nifttl<commit_after>import inspect
import os
import random
import rdflib
import re
import subprocess
import sys
import unittest

rdflib.plugin.register('nifttl', rdflib.serializer.Serializer, 'pyontutils.ttlser', 'CustomTurtleSerializer')

class TestTtlser(unittest.TestCase):
    def setUp(self):

        goodpath = 'test/good.ttl'
        self.badpath = 'test/nasty.ttl'
        actualpath = 'test/actual.ttl'
        self.actualpath2 = 'test/actual2.ttl'

        print(self.make_ser())

        with open(goodpath, 'rb') as f:
            self.good = f.read()

        self.actual = self.serialize()
        with open(actualpath, 'wb') as f:
            f.write(self.actual)
        

    def test_ser(self):
        assert self.actual == self.good

    def serialize(self):
        graph = rdflib.Graph()
        graph.parse(self.badpath, format='turtle')
        actual = graph.serialize(format='nifttl')
        #actual = graph.serialize(format='turtle')  # no change when the file is identical
        return actual

    def make_ser(self):
        header = ('import rdflib\n'
                  'import sys\n'
                  "rdflib.plugin.register('nifttl', rdflib.serializer.Serializer, 'pyontutils.ttlser', 'CustomTurtleSerializer')\n"
                  'class Thing:\n'
                  '    badpath = \'%s\'\n') % self.badpath
        src = inspect.getsource(self.serialize)
        after =  't = Thing()\nsys.stdout.buffer.write(t.serialize())\n'
        return header + src + after


    def test_deterministic(self):
        nofail = True
        env = os.environ.copy()
        seed = None  # 'random'
        for _ in range(10):
            if seed is not None:
                env['PYTHONHASHSEED'] = str(seed)
            else:
                env.pop('PYTHONHASHSEED', None)
            cmd_line = [sys.executable, '-c', self.make_ser()]
            p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
{'fraction_non_alphanumeric': 0.12093261593645914, 'fraction_numerical': 0.0020497053548552396, 'mean_word_length': 2.1817440912795436, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4398255', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1215, 'n_words': 257}