юниттесты, пока не рабочие

This commit is contained in:
sitisll
2023-02-27 18:02:26 +03:00
parent 31d4baebdb
commit d7174a7b57
2 changed files with 92 additions and 18 deletions

58
hlna.py
View File

@ -16,7 +16,6 @@ home_dir = Path.home()
dir_server = f"{home_dir}/ARK_Servers/"
config_hlna = f"{home_dir}/.config/hlna/"
"Убрать"
mods_id = ""
listen_server = True
@ -39,7 +38,6 @@ def find_file(path):
list_config = find_file(config_hlna)
delist_config = find_file(config_hlna+"deactivated")
@ -49,8 +47,6 @@ def print_line(text):
print(f"{colorama.Fore.GREEN} + {text}")
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
print_line(f"list_config=, {list_config}")
def create_dir(directory):
"""Проверка и создание директории"""
@ -78,14 +74,15 @@ create_dir(config_hlna)
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
def config(name_server=list_config):
port_s = []
query_p = []
id_srv = {}
def config(list_config=list_config):
data = {}
cluster_dir_override = ""
cluster_id = ""
id_srv = {}
port_s = []
rcon_p = []
query_p = []
cluster_id = ""
cluster_dir_override = ""
count_cluster = check_int("""Укажите требуется ли кластер?
1. Да
@ -100,7 +97,7 @@ def config(name_server=list_config):
else:
cluster_server = False
if name_server != []:
if list_config:
print("Уже установленные карты: ")
for i in name_server:
data = read_yaml(i)
@ -135,12 +132,13 @@ def config(name_server=list_config):
if 0 < amount_map <= 12:
break
if name_server != []:
for i in name_server:
if list_config:
for i in list_config:
data = read_yaml(i)
port_s.append(data['Port'])
query_p.append(data['QueryPort'])
rcon_p.append(data['RCONPort'])
query_p.append(data['QueryPort'])
if amount_map == 1:
map_s = "TheIsland"
@ -170,8 +168,24 @@ def config(name_server=list_config):
# Если вдруг каким-то боком проверка не отработает и не будет нужной цифры
map_s = 'TheIsland'
if name_server != []:
data = read_yaml(name_server[-1])
def ports(ports_arr):
while True:
port = check_int("")
if port == 0:
if not ports_arr:
print("Значение по умолчаню")
else:
port = max(ports_arr + 2)
if port in ports_arr:
print("Порт уже занят")
else:
return port
if list_config:
data = read_yaml(list_config[-1])
name_server.append(input("Укажите название Сервера: \n"))
if name_server[-1] == '':
if map_s in name_server:
@ -179,6 +193,16 @@ def config(name_server=list_config):
else:
name_server.pop(); name_server.append(map_s) # если enter, то ставим последним элементом карту
port_server = ports(port_s)
query_port = ports(query_p)
if port_server == 0:
port_server = 7777
if query_port == 0:
query_port = 27015
print("Порт Сервера=",port_server)
print("Query Port=", query_port)
'''
while True:
port_server = check_int("Укажите порт Сервера <7777>: \n")
if port_server == 0:
@ -202,7 +226,7 @@ def config(name_server=list_config):
print("Этот порт уже занят")
else:
break
'''
rcon_enabled = True
if rcon_p == []:
rcon_port = 27020

50
pytest.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
from colorama import Fore, Style
import os
import unittest
import time
from threading import Thread
import hlna
"---------------import подменяем через unittest.mock -----------------------"
"---------------------------------------------------------------------------"
def config():
x = os.system("./hlna.py config < 1")
print("x=", x)
def servers():
x = os.system("./hlna.py servers")
if x == 0:
print("Servers - "+Fore.GREEN + "OK" + Style.RESET_ALL)
else:
print(Fore.RED + "Servers Fail" + Style.RESET_ALL)
def delete():
print("Delete - " + Fore.RED + "False" + Style.RESET_ALL)
class TestHlna(unittest.TestCase):
def test_config(self):
pass
# self.assert _input(hlna.config(input(1), 11))
def test_servers(self):
pass
def test_enablemap(self):
passs
def test_start(self):
pass
def test_delete(self):
pass
def test_rcon(self):
pass
if __name__ == "__main__":
#unittest.main()
servers()
config()
delete()
#print(f"{Fore.GREEN} + {text}")
#print(Fore.YELLOW + "-"*30 + Style.RESET_ALL)