Skip to content

Commit

Permalink
Addition of additional tests. Additions of waiting for commands in "P…
Browse files Browse the repository at this point in the history
…ushManager". Bug fixes in "ConsoleManager". Small changes.
  • Loading branch information
enexety committed Sep 30, 2023
1 parent 4cce157 commit e47261d
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 23 deletions.
22 changes: 22 additions & 0 deletions Tests/Unit Testing/test_center_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import sys
import tkinter

sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__), '../../../sources/Overwatch Rank Tracker')))
import MainWindow # noqa: E402


def test_center_window():
"""Check that the window is created in the center of the screen."""

# create window
test_window = tkinter.Tk()

# calling window centering function
MainWindow.MainWindow.center_window(window=test_window, window_height=123, window_width=456)

# getting window coordinates after centering
x_coord = test_window.winfo_x()
y_coord = test_window.winfo_y()

assert (x_coord, y_coord) == (0, 0)
49 changes: 49 additions & 0 deletions Tests/Unit Testing/test_create_and_configure_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import sys
import tkinter
from unittest.mock import patch
from tkinter import ttk # noqa: F401

sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__), '../../../sources/Overwatch Rank Tracker')))
import MainWindow # noqa: E402


def setup_main_window_with_mock():
"""Running the 'create_and_configure_window' function using mocking,
as the 'iconphoto' method cannot be called within unit testing, due to the absence of an actual application window."""

# creating an instance of a class
mainWindow = MainWindow.MainWindow()

# since there is no actual window in the tests, the "iconphoto" method cannot be applied, so it is mocked here
with patch.object(tkinter.Tk, 'iconphoto'):
mainWindow.create_and_configure_window()

return mainWindow


def test_window_created():
"""Checking that the window is actually created."""

mainWindow = setup_main_window_with_mock()
assert isinstance(mainWindow.main_window, tkinter.Tk)


def test_window_title():
"""Checking that the window has the desired name."""

mainWindow = setup_main_window_with_mock()
assert mainWindow.main_window.title() == 'Overwatch Rank Tracker'


def test_window_style():
"""Checking that the styles have been configured correctly."""

mainWindow = setup_main_window_with_mock()

# get styles
style = tkinter.ttk.Style(mainWindow.main_window)
actual_styles = {'background': style.lookup('Treeview', 'background'), 'foreground': style.lookup('Treeview', 'foreground'), 'fieldbackground': style.lookup('Treeview', 'fieldbackground')}
expected_styles = {'background': '#2B2B2B', 'foreground': 'white', 'fieldbackground': '#2B2B2B'}

assert actual_styles == expected_styles
2 changes: 1 addition & 1 deletion Tests/Unit Testing/test_overwriting_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__), '../../../sources/Overwatch Rank Tracker')))
import FileManager # noqa: E402. It imports it and recognizes it, I don't know why the Python interpreter is flagging an error
import FileManager # noqa: E402


"""
Expand Down
51 changes: 51 additions & 0 deletions Tests/Unit Testing/test_set_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__), '../../../sources/Overwatch Rank Tracker')))
import FileManager # noqa: E402


path_to_file_test = os.path.abspath(os.path.join(__file__, '../../test_settings_and_battle_tags.json'))


def test_set_settings_value_change():
"""Checks for changes to settings variables after using the "set_settings" function."""

# define a class
filemanager = FileManager.FileManager()

# value change
filemanager.path_to_file = path_to_file_test
filemanager.max_workers = 3

# create file
filemanager.overwriting_file(full_rewrite=True)

# value change, max_workers in file = 3, in class = 6
filemanager.max_workers = 6

# set settings, max_workers should now be set to 2
filemanager.set_settings()

# delete file
os.remove(path_to_file_test)

assert filemanager.max_workers == 3


def test_set_settings_no_file():
"""Checks that after using the "set_settings" function a file with settings is created, if it was not there before."""

# define a class
filemanager = FileManager.FileManager()

# value change
filemanager.path_to_file = path_to_file_test

# set settings, max_workers should now be set to 2
filemanager.set_settings()

assert os.path.exists(filemanager.path_to_file)

# delete file
os.remove(path_to_file_test)
4 changes: 2 additions & 2 deletions sources/Overwatch Rank Tracker/ButtonManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def __init__(self, mainWindow):
self.private_profiles = []
self.error_battle_tags = []

def set_button_frame(self, main_window):
def set_button_frame(self):
"""Creates a frame for the buttons."""

self.button_frame = tkinter.Frame(main_window, bg='#2B2B2B')
self.button_frame = tkinter.Frame(self.mainWindow.main_window, bg='#2B2B2B')
self.button_frame.pack(side='bottom', fill='x')

def set_buttons(self):
Expand Down
9 changes: 4 additions & 5 deletions sources/Overwatch Rank Tracker/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MainWindow:

def __init__(self, logManager):
def __init__(self, logManager=None):
self.logManager = logManager
self.main_window = None
self.widgetManager = None
Expand All @@ -19,7 +19,7 @@ def run(self):
"""Start the main window and create everything you need on it: frames, buttons, widgets, custom closing."""

# configure window
self.__create_and_configure_window()
self.create_and_configure_window()

# set settings
self.fileManager = FileManager.FileManager()
Expand All @@ -33,7 +33,7 @@ def run(self):

# set frame and buttons
buttonManager = ButtonManager.ButtonManager(mainWindow=self)
buttonManager.set_button_frame(main_window=self.main_window)
buttonManager.set_button_frame()
buttonManager.set_buttons()

# custom close
Expand All @@ -42,15 +42,14 @@ def run(self):
# launch window
self.main_window.mainloop()

def __create_and_configure_window(self):
def create_and_configure_window(self):
"""Create: main window, title, style, centering, logo."""

# create
self.main_window = tkinter.Tk()
self.main_window.title('Overwatch Rank Tracker')

# set style
self.main_window.configure(bg='#2B2B2B')
style = ttk.Style(self.main_window)
style.theme_use("clam")
style.configure('Treeview', background='#2B2B2B', foreground="white", fieldbackground="#2B2B2B")
Expand Down
2 changes: 1 addition & 1 deletion sources/Project Manager/ConsoleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def push_replacing_last_commit(self):
elif userChoice.lower() == 'y':
replacing_commit_message = input('\nCommands:'
"\n1. Back\n"
'\nAre you want to change last commit message? (y/n): ')
'\nCommit message: ')

# user wants to finish
if replacing_commit_message == '1':
Expand Down
9 changes: 5 additions & 4 deletions sources/Project Manager/ProjectManager.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import configparser
import os
import sys

import ConsoleManager
import TokenManager


class ReleaseCreator:
class ProjectManager:

def __init__(self):

# get paths
self.project_directory_path = os.path.abspath(os.path.join(os.path.abspath(__file__), '../../..'))
self.project_directory_path = os.path.abspath(os.path.join(sys.argv[0], '../../..'))
self.zip_file_path = os.path.join(self.project_directory_path, "Overwatch Rank Tracker.zip")
config_file_path = os.path.join(self.project_directory_path, 'resources', 'config.ini')

Expand All @@ -37,5 +38,5 @@ def run(self):


if __name__ == "__main__":
releaseCreator = ReleaseCreator()
releaseCreator.run()
projectManager = ProjectManager()
projectManager.run()
25 changes: 15 additions & 10 deletions sources/Project Manager/PushManager.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import os
import subprocess
import time


class PushManager:

@staticmethod
def __git_add():
def change_work_dir():
""""""

os.chdir('../..')
print(os.getcwd())

def __git_add(self):
"""Executing terminal command - git add ."""

subprocess.run(["git", "add", "."])
self.change_work_dir()
subprocess.run(["git", "add", "."], check=True)

def push_new_commit(self, commit_message: str):
"""Commands to create a new commit."""

self.__git_add()
subprocess.run(["git", "commit", "-m", commit_message])
subprocess.run(["git", "push", "origin", "master"])
time.sleep(3)
subprocess.run(["git", "commit", "-m", commit_message], check=True)
subprocess.run(["git", "push", "origin", "master"], check=True)

def push_replacing_last_commit(self, commit_message: str = None):
"""Commands to replace last commit and possibly its message."""
Expand All @@ -25,11 +31,10 @@ def push_replacing_last_commit(self, commit_message: str = None):

# without replacing commit message
if commit_message is None:
subprocess.run(["git", "commit", "--amend", "-C", "HEAD"])
subprocess.run(["git", "commit", "--amend", "-C", "HEAD"], check=True)

# replacing commit message
else:
subprocess.run(["git", "commit", "--amend", "-m", commit_message])
subprocess.run(["git", "commit", "--amend", "-m", commit_message], check=True)

subprocess.run(["git", "push", "--force"])
time.sleep(3)
subprocess.run(["git", "push", "--force"], check=True)

0 comments on commit e47261d

Please sign in to comment.