Skip to content

Commit

Permalink
Make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
SavageCore committed Sep 14, 2023
1 parent ae9b198 commit f245927
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/gui.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import pytest
import sys
from PyQt5 import QtCore, QtWidgets
from pytestqt.qtbot import QtBot
from torfGUI.gui import TorfGUI

from torfGUI import __version__
from torfGUI.gui import TorfGUI

PROGRAM_NAME = "torf-gui"
PROGRAM_NAME_VERSION = "{} {}".format(PROGRAM_NAME, __version__)


@pytest.fixture
def app(qtbot: QtBot):
# Setup
Expand All @@ -22,6 +23,7 @@ def app(qtbot: QtBot):
MainWindow.show()

import os

if not os.path.exists("tmp"):
os.makedirs("tmp")
if not os.path.exists("tmp/test_dir"):
Expand All @@ -36,29 +38,34 @@ def app(qtbot: QtBot):
# Run
yield torf


# GUI loads
def test_load(app):
assert app is not None


# GUI loads with correct title
def test_title(app):
assert app.MainWindow.windowTitle() == PROGRAM_NAME_VERSION


# Batch mode checkbox appears when Directory is selected
def test_batch_checkbox(app, qtbot):
assert app.batchModeCheckBox.isVisible() == False
assert app.batchModeCheckBox.isVisible() is False

qtbot.mouseClick(app.directoryRadioButton, QtCore.Qt.LeftButton)

assert app.batchModeCheckBox.isVisible()


# Piece size is disabled when Directory Batch mode is selected
def test_piece_size(app, qtbot):
assert app.pieceSizeComboBox.isEnabled()

qtbot.mouseClick(app.directoryRadioButton, QtCore.Qt.LeftButton)
qtbot.mouseClick(app.batchModeCheckBox, QtCore.Qt.LeftButton)
assert app.pieceSizeComboBox.isEnabled() == False
assert app.pieceSizeComboBox.isEnabled() is False


# Reset button resets the GUI
def test_reset(app, qtbot):
Expand All @@ -67,38 +74,41 @@ def test_reset(app, qtbot):

qtbot.mouseClick(app.resetButton, QtCore.Qt.LeftButton)

assert app.directoryRadioButton.isChecked() == False
assert app.directoryRadioButton.isChecked() is False


# Create button is disabled when no input is given
def test_create_button_disabled(app, qtbot):
def test_create_button_disabled(app):
assert app.inputEdit.text() == ""
assert app.createButton.isEnabled() == False
assert app.createButton.isEnabled() is False

app.inputEdit.setText("tmp/test_dir/test_file.txt")
app.initializeTorrent()

assert app.createButton.isEnabled()


# Piece size is calculated correctly for a file
def test_piece_size_file(app, qtbot):
def test_piece_size_file(app):
app.inputEdit.setText("tmp/test_dir/test_file.txt")
app.initializeTorrent()

assert app.pieceCountLabel.text() == "16384 pieces @ 1 byte each"


# File size is calculated correctly for a file
def test_file_size_file(app, qtbot):
def test_file_size_file(app):
app.inputEdit.setText("tmp/test_dir/test_file.txt")
app.initializeTorrent()

assert app.MainWindow.statusBar().currentMessage() == "test_file.txt: 4 bytes"
assert (
app.MainWindow.statusBar().currentMessage() == "test_file.txt: 4 bytes"
)


# File size is calculated correctly for a folder
def test_file_size_file(app, qtbot):
def test_file_size_folder(app):
app.inputEdit.setText("tmp/test_dir")
app.initializeTorrent()

assert app.MainWindow.statusBar().currentMessage() == "test_dir: 8 bytes"

# # Options are remembered when re-opening the app
# def test_options_remembered(app, qtbot):

0 comments on commit f245927

Please sign in to comment.