<commit_before>import unittest
from .test_git_util import MyTestGitUtilBase
import os

from .. import unpack_ipynb as unpack
import math


class TestUnpackIpythonNotebookOneFile(MyTestGitUtilBase):
    def setUp(self):
        super(TestUnpackIpythonNotebookOneFile, self).setUp()

        self.test_file_name = tuple([os.path.join(self.test_path, filename) for filename in ('test_unpack_00', 'test_unpack_01')])
        self.sample_file_indicator = 'sample'
        self.python_ext = 'py'
        self.notebook_ext = 'ipynb'
        self.sample_ext = 'txt'

        self.del_py_if_exists()

    def del_py_if_exists(self):
        for test_file_name in self.test_file_name:
            expected_py_name = self.make_py_full_path(test_file_name)
            if os.path.exists(expected_py_name):
                os.remove(expected_py_name)

    def make_py_full_path(self, test_file_name):
        return os.path.abspath('.'.join((test_file_name, self.python_ext)))

    def make_sample_file_name(self, test_file_name):
        return '_'.join((test_file_name, self.sample_file_indicator))

    def test_unpack(self):
        for test_file_name in self.test_file_name:
            expected_py_name = self.make_py_full_path(test_file_name)
            test_sample_file_name = self.make_sample_file_name(test_file_name)
            expected_py_sample_name = os.path.abspath('.'.join((test_sample_file_name, self.sample_ext)))
            expected_nb_name = os.path.abspath('.'.join((test_file_name, self.notebook_ext)))

            if not os.path.exists(expected_nb_name):
                raise IOError("File %.150s missing \n__file__ = %s" % (expected_nb_name, __file__))

            # function under tests
            unpack.unpack(expected_nb_name, b_verbose=True)

            with open(expected_py_name, encoding='utf8') as py_file:
                py_txt = py_file.readlines()

                with open(expected_py_sample_name, encoding='utf8') as py_sample_file:
                    py_sample_txt = py_sample_file.readlines()
<commit_msg>use __file__ to generate test_file_name<commit_after>import unittest
from .test_git_util import MyTestGitUtilBase
import os

from .. import unpack_ipynb as unpack
import math


class TestUnpackIpythonNotebookOneFile(MyTestGitUtilBase):
    def setUp(self):
        super(TestUnpackIpythonNotebookOneFile, self).setUp()

        # update self.test_file_path if necessary
        if os.path.split(__file__)[0] != self.test_file_path:
            self.test_file_path = os.path.split(__file__)[0]

        self.test_file_name = tuple([os.path.join(self.test_file_path, filename) for filename in ('test_unpack_00', 'test_unpack_01')])
        self.sample_file_indicator = 'sample'
        self.python_ext = 'py'
        self.notebook_ext = 'ipynb'
        self.sample_ext = 'txt'

        self.del_py_if_exists()

    def del_py_if_exists(self):
        for test_file_name in self.test_file_name:
            expected_py_name = self.make_py_full_path(test_file_name)
            if os.path.exists(expected_py_name):
                os.remove(expected_py_name)

    def make_py_full_path(self, test_file_name):
        return os.path.abspath('.'.join((test_file_name, self.python_ext)))

    def make_sample_file_name(self, test_file_name):
        return '_'.join((test_file_name, self.sample_file_indicator))

    def test_unpack(self):
        for test_file_name in self.test_file_name:
            expected_py_name = self.make_py_full_path(test_file_name)
            test_sample_file_name = self.make_sample_file_name(test_file_name)
            expected_py_sample_name = os.path.abspath('.'.join((test_sample_file_name, self.sample_ext)))
            expected_nb_name = os.path.abspath('.'.join((test_file_name, self.notebook_ext)))

            if not os.path.exists(expected_nb_name):
                raise IOError('''File %.150s missing
__file__ = %s
self.test_file_path = %s''' % (expected_nb_name, __file__, self.test_file_path))

            # function under tests
            unpack.unpack(expected_nb_name, b_verbose=True)

            with open(expected_py_name, encoding='utf8') as py_file:
                py_txt = py_file.readlines()

                with open(expected_py_sample_name, encoding='utf8') as py_sample_file:
                    py_sample_txt = py_sample_file.readlines()

{'fraction_non_alphanumeric': 0.09536973047684866, 'fraction_numerical': 0.0046072333563695, 'mean_word_length': 3.1590038314176243, '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': '3202937', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1411, 'n_words': 230}