Skip to content

Commit

Permalink
Devel (#83)
Browse files Browse the repository at this point in the history
* dev updates

* update

* Converted Magnet tab to tool tab

* Final push for 0.3.6

* Final push for 0.3.6
  • Loading branch information
alexpdev committed Aug 23, 2022
1 parent c023999 commit 71e065c
Show file tree
Hide file tree
Showing 18 changed files with 1,630 additions and 1,291 deletions.
871 changes: 489 additions & 382 deletions coverage.xml

Large diffs are not rendered by default.

19 changes: 2 additions & 17 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from torrentfileQt import Application

APP = Application([])
# APP.window.show()


def exception_hook(exctype, value, traceback): # pragma: no cover
Expand Down Expand Up @@ -295,23 +296,7 @@ def mime_data(self):
mimeData = mime_data


class MockQFileDialog:
"""Mock object for the QFileDialog."""

Out = None

@classmethod
def getOpenFileName(cls, parent=None, dir=None, caption=None):
"""Mock class method for returning file path from file dialog."""
assert isinstance(caption, str)
assert dir
cls.parent = parent
return cls.Out

getExistingDirectory = getOpenFileName


def proc_time(amount=0.1):
def proc_time(amount=0.01):
"""Process time span with updating GUI."""
then = time.time()
APP.processEvents()
Expand Down
10 changes: 1 addition & 9 deletions tests/test_checktab.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
import os
from pathlib import Path

import PySide6
import pytest

from tests import (MockQFileDialog, dir1, dir2, proc_time, rmpath, tempfile,
ttorrent, wind)
from torrentfileQt import checkTab
from tests import dir1, dir2, proc_time, rmpath, tempfile, ttorrent, wind
from torrentfileQt.checkTab import ProgressBar, TreePieceItem, TreeWidget


Expand Down Expand Up @@ -89,8 +86,6 @@ def test_check_tab(wind, ttorrent, dir1):
def test_check_tab_input1(wind, dir1):
"""Test checker procedure."""
checktab = wind.central.checkWidget
MockQFileDialog.Out = dir1
PySide6.QtWidgets.QFileDialog = MockQFileDialog
wind.central.setCurrentWidget(checktab)
checktab.browseButton2.browse_folders(dir1)
assert checktab.searchInput.text() != ""
Expand All @@ -99,8 +94,6 @@ def test_check_tab_input1(wind, dir1):
def test_check_tab_input_2(wind, dir1):
"""Test checker procedure."""
checktab = wind.central.checkWidget
MockQFileDialog.Out = dir1
PySide6.QtWidgets.QFileDialog = MockQFileDialog
wind.central.setCurrentWidget(checktab)
checktab.browseButton1.browse((dir1, None))
assert checktab.fileInput.text() != ""
Expand Down Expand Up @@ -147,7 +140,6 @@ def test_singlefile(size, ext, index, version, wind):
testfile = str(tempfile(exp=size))
tfile = testfile + ext
os.rename(testfile, tfile)
checkTab.QFileDialog = MockQFileDialog
metafile = tfile + ".torrent"
createtab.path_input.clear()
createtab.output_input.clear()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_createTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import pyben
import pytest
from torrentfile.torrent import TorrentFileHybrid

from tests import dir1, dir2, proc_time, rmpath, tempfile, wind
from torrentfileQt.createTab import TorrentFileCreator


def test_rmpath():
Expand Down Expand Up @@ -143,3 +145,12 @@ def test_sized_create(wind):
button.browse(param)
proc_time()
assert createtab.path_input.text() == path


def test_torrentfile_creator(dir1):
"""Test the QThread torrent file creator."""
args = {"path": dir1, "outfile": dir1 + ".torrent"}
creator = TorrentFileCreator(args, TorrentFileHybrid)
creator.run()
assert os.path.exists(dir1 + ".torrent")
rmpath(dir1 + ".torrent")
1 change: 1 addition & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ def test_styleManager():
manager = StyleManager(themes)
manager.current = themes["test"]
collection = manager.parser.parse(themes["test"])
manager.parser._compile()
assert len(collection) > 1
70 changes: 48 additions & 22 deletions tests/test_magnettab.py → tests/test_tooltab.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,68 +44,94 @@ def torrent(dir1):

def test_fixture():
"""Testing pytest fixtures."""
assert [dir1, tempfile, wind, ttorrent, dir2]
assert [dir1, dir2, tempfile, wind, ttorrent]


def test_create_magnet(wind, torrent):
"""Test creating Magnet URI from a torrent file path."""
outfile, _ = torrent
tab = wind.central.magnetWidget
tab = wind.central.toolWidget
wind.central.setCurrentWidget(tab)
tab.metafile_input.setText(str(outfile))
tab.submit_button.click()
out = tab.output.text()
widget = tab.magnetgroup
widget.pathEdit.setText(str(outfile))
widget.submit_button.click()
out = widget.magnetEdit.text()
proc_time()
assert out == magnet(outfile)


def test_create_magnet_method(wind, torrent):
"""Test creating Magnet URI from a torrent file path."""
outfile, _ = torrent
tab = wind.central.magnetWidget
tab = wind.central.toolWidget
wind.central.setCurrentWidget(tab)
tab.file_button.select_metafile(outfile)
tab = tab.magnetgroup
tab.metafilebutton.select_metafile(outfile)
tab.submit_button.magnet()
out = tab.output.text()
out = tab.magnetEdit.text()
proc_time()
assert out == magnet(outfile)


def test_magnet_accept_method(wind, ttorrent):
"""Test drag enter event on editor widget."""
magnet = wind.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
tab = wind.central.toolWidget
tab.window.central.setCurrentWidget(tab)
proc_time()
event = MockEvent(ttorrent)
assert magnet.dragEnterEvent(event)
assert tab.magnetgroup.dragEnterEvent(event)
event = MockEvent(None)
assert not magnet.dragEnterEvent(event)
assert not tab.magnetgroup.dragEnterEvent(event)


def test_magnet_move_event(wind, ttorrent):
"""Test move event on magnet widget."""
magnet = wind.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
tools = wind.central.toolWidget
tools.window.central.setCurrentWidget(tools)
proc_time()
event = MockEvent(ttorrent)
assert magnet.dragMoveEvent(event)
assert tools.magnetgroup.dragMoveEvent(event)
event = MockEvent(None)
assert not magnet.dragMoveEvent(event)
assert not tools.magnetgroup.dragMoveEvent(event)


def test_magnet_drop_event(wind, ttorrent):
"""Test drop event on editor widget."""
magnet = wind.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
tools = wind.central.toolWidget
tools.window.central.setCurrentWidget(tools)
proc_time()
event = MockEvent(ttorrent)
assert magnet.dropEvent(event)
assert tools.magnetgroup.dropEvent(event)


def test_magnet_drop_false(wind):
"""Test drop event on editor widget returns None."""
magnet = wind.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
tools = wind.central.toolWidget
tools.window.central.setCurrentWidget(tools)
proc_time()
event = MockEvent(None)
assert not magnet.dropEvent(event)
assert not tools.magnetgroup.dropEvent(event)


def test_piecelengthcalculator(wind, dir1):
"""Test the piece length calculator."""
tools = wind.central.toolWidget
tools.window.central.setCurrentWidget(tools)
proc_time()
calculator = tools.piece_length_calculator
calculator.browse_folders(dir1)
assert calculator.path_line.text() == dir1


def test_piecelengthcalculator_file(wind):
"""Test the piece length calculator with a single file."""
widget = wind.central.toolWidget
widget.window.central.setCurrentWidget(widget)
proc_time()
calculator = widget.piece_length_calculator
temp = str(tempfile())
calculator.browse_files(temp)
assert calculator.path_line.text() == temp
calculator.piece_length_combo.setCurrentIndex(3)
calculator.calculate_piece_length()
rmpath(temp)
Binary file added torrentfileQt/assets/minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified torrentfileQt/assets/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion torrentfileQt/checkTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __init__(self, parent=None):
self.setIcon(QIcon(get_icon("browse_file")))
self.clicked.connect(self.browse_files)

def browse_files(self, path=None):
def browse_files(self, path=None): # pragma: nocover
"""
Browse Action performed when user presses button.
"""
Expand Down
11 changes: 5 additions & 6 deletions torrentfileQt/createTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class TorrentFileCreator(QThread):
container to add return values to
"""

created = Signal([str])
created = Signal()

def __init__(self, args, creator):
"""Construct the new thread."""
Expand All @@ -194,8 +194,8 @@ def run(self):
"""Create a torrent file and emit it's path."""
args = deepcopy(self.args)
torrent = self.creator(**args)
outfile, _ = torrent.write()
self.created.emit(outfile)
_, _ = torrent.write()
self.created.emit()


class SubmitButton(QPushButton):
Expand Down Expand Up @@ -279,10 +279,9 @@ def updateStatusBarBegin(self):
"""Update the status bar when torrent creation is complete."""
self.window.statusBar().showMessage("Processing", 3000)

def updateStatusBarEnd(self, string):
def updateStatusBarEnd(self):
"""Update the status bar when torrent creation is complete."""
message = f"Finished creating torrent file: {string}"
self.window.statusBar().showMessage(message, 3000)
self.window.statusBar().showMessage("Completed", 3000)


class OutButton(QPushButton):
Expand Down
24 changes: 13 additions & 11 deletions torrentfileQt/editorTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

import pyben
from PySide6.QtCore import Qt, Signal
from PySide6.QtGui import QAction
from PySide6.QtGui import QAction, QIcon
from PySide6.QtWidgets import (QComboBox, QHBoxLayout, QLabel, QLineEdit,
QPushButton, QSizePolicy, QTableWidget,
QTableWidgetItem, QToolBar, QToolButton,
QVBoxLayout, QWidget)
QTableWidgetItem, QToolBar, QVBoxLayout,
QWidget)

from torrentfileQt.utils import browse_torrent
from torrentfileQt.utils import browse_torrent, get_icon


class EditorWidget(QWidget):
Expand Down Expand Up @@ -141,14 +141,15 @@ def save(self):
pyben.dump(meta, text)


class FileButton(QToolButton):
class FileButton(QPushButton):
"""Tool Button for selecting a .torrent file to edit."""

def __init__(self, parent=None):
"""Construct for the FileDialog button on Torrent Editor tab."""
super().__init__(parent=parent)
self.widget = parent
self.setText("Select File")
self.setIcon(QIcon(get_icon("browse_file")))
self.setText("File")
self.window = parent.window
self.clicked.connect(self.browse)

Expand All @@ -168,7 +169,6 @@ def __init__(self, parent):
super().__init__(parent)
self.setProperty("editButton", "true")
self.parent = parent
self.setText("add")
self.box = None
self.triggered.connect(self.add_item)

Expand All @@ -191,7 +191,6 @@ def __init__(self, parent):
super().__init__(parent)
self.setProperty("editButton", "true")
self.parent = parent
self.setText("remove")
self.box = None
self.triggered.connect(self.remove_item)

Expand Down Expand Up @@ -220,7 +219,6 @@ def __init__(self, parent=None):
vheader = self.verticalHeader()
vheader.setSectionResizeMode(vheader.ResizeMode.Stretch)
vheader.setHidden(True)
self.setHorizontalHeaderLabels(["Label", "Value"])
self.handleTorrent.connect(self.export_data)

def clear(self):
Expand All @@ -230,6 +228,7 @@ def clear(self):
self.removeRow(row)
self.setRowCount(0)
super().clear()
self.setHorizontalHeaderLabels(["Label", "Value"])

def export_data(self, path):
"""Export slot for the handleTorrent signal."""
Expand Down Expand Up @@ -287,7 +286,6 @@ def __init__(self, parent=None):
"""Construct a combobox for table widget cell."""
super().__init__(parent=parent)
self.widget = parent
self.setProperty("editCombo", "true")
self.sizePolicy().setVerticalPolicy(QSizePolicy.Minimum)
self.setMinimumContentsLength(48)
self.sizePolicy().setHorizontalPolicy(QSizePolicy.Minimum)
Expand Down Expand Up @@ -318,15 +316,19 @@ class ToolBar(QToolBar):
def __init__(self, parent=None):
"""Construct the toolbar instance."""
super().__init__(parent=parent)
self.setProperty("editToolBar", "true")
self.sizePolicy().setHorizontalPolicy(QSizePolicy.Minimum)
self.setMinimumWidth(800)
self.line_edit = QLineEdit(parent=self)
self.combo = Combo(self)
self.combo.setLineEdit(self.line_edit)
self.setProperty("editLine", "true")
self.add_button = AddItemButton(self)
addIcon = QIcon(get_icon("plus"))
self.add_button.setIcon(addIcon)
self.add_button.box = self.combo
self.remove_button = RemoveItemButton(self)
removeIcon = QIcon(get_icon("minus"))
self.remove_button.setIcon(removeIcon)
self.remove_button.box = self.combo
self.addWidget(self.combo)
self.addActions([self.add_button, self.remove_button])
Expand Down
Loading

0 comments on commit 71e065c

Please sign in to comment.