Merge branch 'master' into VIS-24

This commit is contained in:
Helena Gałązka 2021-01-04 12:24:16 +01:00
commit ebba0059e2
3 changed files with 108 additions and 41 deletions

Binary file not shown.

View File

@ -1,7 +1,9 @@
#import tkinter as tk
import sys
import os
import shutil
from datetime import datetime
import time
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon, QPixmap
@ -15,6 +17,16 @@ def files(path):
if os.path.isfile(os.path.join(path, file)):
yield file
def save_input(oldpath):
# make timestampt the filename, so it wouln't overwrite
timestamp = str(int(time.time()))
filename = timestamp + '.' + oldpath.split('.')[-1]
newpath = filePath + '\\' + filename
shutil.copy(oldpath, newpath)
return newpath
class LibraryTableButtons(QWidget):
def __init__(self, filename, parent=None):
super(LibraryTableButtons,self).__init__(parent)
@ -39,7 +51,9 @@ class LibraryTableButtons(QWidget):
self.setLayout(layout)
class LibraryTable(QTableWidget):
def __init__(self, parent=None):
QTableWidget.__init__(self)
self.setColumnCount(3)
@ -62,50 +76,63 @@ class LibraryTable(QTableWidget):
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
def main():
app = QApplication(sys.argv)
class MainWindow(QMainWindow):
#w = QWidget()
w = QMainWindow()
w.setGeometry(0, 0, 600, 400)
w.setWindowTitle('VisionScore')
scriptDir = os.path.dirname(os.path.realpath(__file__))
w.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
'''
label = QLabel()
pixmap = QPixmap(scriptDir + os.path.sep + 'static/visionscore_logo.jpg')
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.setAlignment(QtCore.Qt.AlignTop)
w.setCentralWidget(label)
'''
# Toolbar
menuBar = w.menuBar()
homeMenu = QMenu("&Home", w)
menuBar.addMenu(homeMenu)
homeMenu.addAction("Load new file")
def __init__(self):
super().__init__()
self.initUI()
# Show raw uploaded files
def showLibrary():
def showLibrary(self):
libTable = LibraryTable()
w.setCentralWidget(libTable)
self.setCentralWidget(libTable)
libraryAct = QAction('&Library', w)
libraryAct.triggered.connect(showLibrary)
def showUploadFile(self):
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.AnyFile)
dialog.setFilter(QDir.Files)
if dialog.exec_():
file_path = dialog.selectedFiles()[0] # ['C:/Users/agatha/Desktop/SYI/VisionScore/win_venv/requirements.txt']
save_input(file_path)
def initUI(self):
self.setGeometry(0, 0, 600, 400)
self.setWindowTitle('VisionScore')
scriptDir = os.path.dirname(os.path.realpath(__file__))
self.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
# Toolbar
menuBar = self.menuBar()
homeMenu = QMenu("&Home", self)
menuBar.addMenu(homeMenu)
# Upload file
uploadAct = QAction('&Upload new file', self)
uploadAct.triggered.connect(self.showUploadFile)
homeMenu.addAction(uploadAct)
libraryAct = QAction('&Library', self)
libraryAct.triggered.connect(self.showLibrary)
menuBar.addAction(libraryAct)
# Exit app
exitAct = QAction('&Exit', w)
exitAct = QAction('&Exit', self)
exitAct.setShortcut('Ctrl+Q')
exitAct.setStatusTip('Exit')
exitAct.triggered.connect(app.quit)
exitAct.triggered.connect(qApp.quit)
homeMenu.addAction(exitAct)
helpMenu = menuBar.addMenu("&Help")
w.show()
self.show()
def main():
app = QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

40
win_venv/tests.py Normal file
View File

@ -0,0 +1,40 @@
import unittest
from main import *
from unittest.mock import Mock
from pathlib import Path
# test saving file
class savingFileTest(unittest.TestCase):
def test_text_file(self):
print('Testing save_input method \n')
old_file_content = 'testing\n\n\nmore testing'
with open('test.txt', 'w') as file:
file.write(old_file_content)
script_path = os.path.dirname(os.path.realpath(__file__))
test_file_path = script_path + '\\test.txt'
newpath = save_input(test_file_path)
new_file_content = ''
with open(newpath, 'r') as new_file:
for line in new_file:
new_file_content += line
self.assertEqual(old_file_content, new_file_content)
# test using mock checking if a file with analysis had been generated
class generetingOutputFile(unittest.TestCase):
def test_output_file(self):
print('Moock testing outputfile')
m = Mock()
m.output_file_path = scriptPath + '\\files\\output\\test.pdf'
assert Path(m.output_file_path).is_file()
if __name__ == '__main__':
unittest.main()