<commit_before>import sys
import unittest
import tempfile
import os
from setuptools.dist import Distribution
from distutils.errors import DistutilsOptionError

sys.path.insert(0, ".")
from coalib.output.dbus.BuildDbusService import BuildDbusService
from coalib.misc import Constants


class BuildDbusServiceTest(unittest.TestCase):

    def test_build(self):
        dist = Distribution()
        uut = BuildDbusService(dist)
        self.assertRaises(DistutilsOptionError, uut.finalize_options)
        handle, uut.output = tempfile.mkstemp(text=True)

        uut.finalize_options()

        uut.run()
        result = os.read(handle, 1000).decode()

        self.assertEqual(
            result,
            "[D-BUS Service]\nNames=" + Constants.BUS_NAME +
            "\nExec=coala-dbus")


if __name__ == "__main__":<commit_msg>BuildDbusServiceTest: Implement make_temp()<commit_after>import sys
import unittest
from setuptools.dist import Distribution
from distutils.errors import DistutilsOptionError

sys.path.insert(0, ".")
from coalib.output.dbus.BuildDbusService import BuildDbusService
from coalib.misc import Constants
from coalib.misc.ContextManagers import make_temp


class BuildDbusServiceTest(unittest.TestCase):

    def test_build(self):
        dist = Distribution()
        uut = BuildDbusService(dist)
        self.assertRaises(DistutilsOptionError, uut.finalize_options)
        with make_temp() as uut.output:
            uut.finalize_options()

            uut.run()
            with open(uut.output) as file:
                result = file.read(1000)

            self.assertEqual(
                result,
                "[D-BUS Service]\nNames=" + Constants.BUS_NAME +
                "\nExec=coala-dbus")


if __name__ == "__main__":
{'fraction_non_alphanumeric': 0.09194097616345062, 'fraction_numerical': 0.0056753688989784334, 'mean_word_length': 2.98868778280543, 'pattern_counts': {'":': 2, '<': 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': '127523', 'n_tokens_mistral': 537, 'n_tokens_neox': 514, 'n_words': 109}