<commit_before># Sheepdog
# Copyright 2013 <NAME>
#
# Released under the MIT license. See LICENSE file for details.

from nose.tools import assert_equal, assert_true

from sheepdog import serialisation

class TestSerialisation:
    def test_serialises_functions(self):
        def myfunc(a, b):
            return a + b
        fs = serialisation.serialise_function(myfunc)
        assert_equal(type(fs), bytes)
        f = serialisation.deserialise_function(fs)
        assert_equal(f(1, 2), myfunc(1, 2))

    def test_serialises_functions_with_namespaces(self):
        def myfunc(a):
            return a + b
        fs = serialisation.serialise_function(myfunc)
        f = serialisation.deserialise_function(fs, {"b": 10})
        assert_equal(f(1), 11)
<commit_msg>test coverage for other-python in serialisation<commit_after># Sheepdog
# Copyright 2013 <NAME>
#
# Released under the MIT license. See LICENSE file for details.

from nose.tools import assert_equal, assert_true

from sheepdog import serialisation

class TestSerialisation:
    def test_serialises_functions(self):
        def myfunc(a, b):
            return a + b
        fs = serialisation.serialise_function(myfunc)
        assert_equal(type(fs), bytes)
        f = serialisation.deserialise_function(fs)
        assert_equal(f(1, 2), myfunc(1, 2))

    def test_serialises_functions_other_python(self):
        # Check it does the right thing for the Python we're not running.
        # Not strictly needed but it gets 100% test coverage!

        def myfunc(a, b):
            return a + b
        
        class FakeFunc:
            pass

        func = FakeFunc()

        if hasattr(myfunc, "__code__"):
            func.func_code = myfunc.__code__
        else:
            func.__code__ = myfunc.func_code

        fs = serialisation.serialise_function(func)
        assert_equal(type(fs), bytes)
        f = serialisation.deserialise_function(fs)
        assert_equal(f(1, 2), myfunc(1, 2))

    def test_serialises_functions_with_namespaces(self):
        def myfunc(a):
            return a + b
        fs = serialisation.serialise_function(myfunc)
        f = serialisation.deserialise_function(fs, {"b": 10})
        assert_equal(f(1), 11)

{'fraction_non_alphanumeric': 0.0870345446388515, 'fraction_numerical': 0.014804845222072678, 'mean_word_length': 2.7542087542087543, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '1349626', 'n_tokens_mistral': 694, 'n_tokens_neox': 662, 'n_words': 175}