Merge branch 'master' into VIS-24
This commit is contained in:
commit
ebba0059e2
BIN
win_venv/files/output/test.pdf
Normal file
BIN
win_venv/files/output/test.pdf
Normal file
Binary file not shown.
107
win_venv/main.py
107
win_venv/main.py
@ -1,7 +1,9 @@
|
|||||||
#import tkinter as tk
|
#import tkinter as tk
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtWidgets import *
|
from PyQt5.QtWidgets import *
|
||||||
from PyQt5.QtGui import QIcon, QPixmap
|
from PyQt5.QtGui import QIcon, QPixmap
|
||||||
@ -15,6 +17,16 @@ def files(path):
|
|||||||
if os.path.isfile(os.path.join(path, file)):
|
if os.path.isfile(os.path.join(path, file)):
|
||||||
yield 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):
|
class LibraryTableButtons(QWidget):
|
||||||
def __init__(self, filename, parent=None):
|
def __init__(self, filename, parent=None):
|
||||||
super(LibraryTableButtons,self).__init__(parent)
|
super(LibraryTableButtons,self).__init__(parent)
|
||||||
@ -39,7 +51,9 @@ class LibraryTableButtons(QWidget):
|
|||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
|
||||||
class LibraryTable(QTableWidget):
|
class LibraryTable(QTableWidget):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTableWidget.__init__(self)
|
QTableWidget.__init__(self)
|
||||||
self.setColumnCount(3)
|
self.setColumnCount(3)
|
||||||
@ -62,50 +76,63 @@ class LibraryTable(QTableWidget):
|
|||||||
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
|
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
# Show raw uploaded files
|
||||||
|
def showLibrary(self):
|
||||||
|
libTable = LibraryTable()
|
||||||
|
self.setCentralWidget(libTable)
|
||||||
|
|
||||||
|
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', self)
|
||||||
|
exitAct.setShortcut('Ctrl+Q')
|
||||||
|
exitAct.setStatusTip('Exit')
|
||||||
|
exitAct.triggered.connect(qApp.quit)
|
||||||
|
homeMenu.addAction(exitAct)
|
||||||
|
|
||||||
|
helpMenu = menuBar.addMenu("&Help")
|
||||||
|
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
#w = QWidget()
|
w = MainWindow()
|
||||||
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")
|
|
||||||
|
|
||||||
# Show raw uploaded files
|
|
||||||
def showLibrary():
|
|
||||||
libTable = LibraryTable()
|
|
||||||
w.setCentralWidget(libTable)
|
|
||||||
|
|
||||||
libraryAct = QAction('&Library', w)
|
|
||||||
libraryAct.triggered.connect(showLibrary)
|
|
||||||
menuBar.addAction(libraryAct)
|
|
||||||
|
|
||||||
# Exit app
|
|
||||||
exitAct = QAction('&Exit', w)
|
|
||||||
exitAct.setShortcut('Ctrl+Q')
|
|
||||||
exitAct.setStatusTip('Exit')
|
|
||||||
exitAct.triggered.connect(app.quit)
|
|
||||||
homeMenu.addAction(exitAct)
|
|
||||||
|
|
||||||
helpMenu = menuBar.addMenu("&Help")
|
|
||||||
|
|
||||||
w.show()
|
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
40
win_venv/tests.py
Normal file
40
win_venv/tests.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user