| 1 |
# SPDX-FileCopyrightText: © 2023 Christian BUHTZ <[email protected]> |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: GPL-3.0-only |
| 4 |
# |
| 5 |
# This file is part of the program "Hyperorg" which is released under GNU |
| 6 |
# General Public License v3 (GPLv3). |
| 7 |
# See folder LICENSES or go to <https://www.gnu.org/licenses/#GPL>. |
| 8 |
"""Test about the hyperorg package (__main__.py)""" |
| 9 |
import unittest |
| 10 |
import subprocess |
| 11 |
import hyperorg |
| 12 |
import hyperorg.__main__ |
| 13 |
|
| 14 |
|
| 15 |
class TestHyperorg(unittest.TestCase): |
| 16 |
"""Tests for __main__.py and __init__.py""" |
| 17 |
|
| 18 |
def _get_git_branch(self): |
| 19 |
return subprocess.check_output( |
| 20 |
['git', 'symbolic-ref', '--short', 'HEAD']) \ |
| 21 |
.decode().replace('\n', '') |
| 22 |
|
| 23 |
def _get_git_commit_hash(self): |
| 24 |
return subprocess.check_output( |
| 25 |
['git', 'log', '-n', '1', '--format=%H']) \ |
| 26 |
.decode().replace('\n', '') |
| 27 |
|
| 28 |
def test_git_repository_info(self): |
| 29 |
"""Git version infos.""" |
| 30 |
self.assertEqual( |
| 31 |
{ |
| 32 |
'branch': self._get_git_branch(), |
| 33 |
'hash': self._get_git_commit_hash()[:8], |
| 34 |
}, |
| 35 |
hyperorg.get_git_repository_info()) |
| 36 |
|
| 37 |
def test_simplify(self): |
| 38 |
"""Remove unusual characters from a string""" |
| 39 |
self.assertEqual( |
| 40 |
hyperorg.simplify_string('<>()ads :-fäÜÖß'), |
| 41 |
'____ads__-fäÜÖß' |
| 42 |
) |