<commit_before># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.
import pytest
from unittest import TestCase, mock
import gosa.dbus.main


class MainTestCase(TestCase):

    def test_main(self):
        with mock.patch("gosa.dbus.main.mainLoop") as m,\
                mock.patch("gosa.dbus.main.os.geteuid", return_value=1) as mg:

            with pytest.raises(SystemExit) as cm:
                gosa.dbus.main.main()
                assert not m.called
                assert cm.exception_code == 1

            mg.return_value = 0

            gosa.dbus.main.main()
            assert m.called<commit_msg>skip dbus test on failed import<commit_after># This file is part of the GOsa framework.
#
#  http://gosa-project.org
#
# Copyright:
#  (C) 2016 GONICUS GmbH, Germany, http://www.gonicus.de
#
# See the LICENSE file in the project's top-level directory for details.
import pytest
from unittest import TestCase, mock
try:
    import gosa.dbus.main
    has_glib = True
except ImportError:
    has_glib = False


@pytest.mark.skipif(has_glib is False, reason="requires gi package")
class MainTestCase(TestCase):

    def test_main(self):
        with mock.patch("gosa.dbus.main.mainLoop") as m,\
                mock.patch("gosa.dbus.main.os.geteuid", return_value=1) as mg:

            with pytest.raises(SystemExit) as cm:
                gosa.dbus.main.main()
                assert not m.called
                assert cm.exception_code == 1

            mg.return_value = 0

            gosa.dbus.main.main()
            assert m.called
{'fraction_non_alphanumeric': 0.1032069970845481, 'fraction_numerical': 0.00816326530612245, 'mean_word_length': 2.345029239766082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1762413', 'n_tokens_mistral': 574, 'n_tokens_neox': 541, 'n_words': 147}