Skip to content

Commit

Permalink
Adding tests. Small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
enexety committed Sep 30, 2023
1 parent 4cce157 commit d190944
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 14 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)
48 changes: 48 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,48 @@
import os
import sys
import tkinter
from unittest.mock import patch
from tkinter import ttk

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():

# 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():
""""""

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


def test_window_title():
""""""

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
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()
7 changes: 5 additions & 2 deletions sources/Project Manager/PushManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ def __git_add():
"""Executing terminal command - git add ."""

subprocess.run(["git", "add", "."])
time.sleep(2)

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

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

def push_replacing_last_commit(self, commit_message: str = None):
"""Commands to replace last commit and possibly its message."""
Expand All @@ -31,5 +33,6 @@ def push_replacing_last_commit(self, commit_message: str = None):
else:
subprocess.run(["git", "commit", "--amend", "-m", commit_message])

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

0 comments on commit d190944

Please sign in to comment.