Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
16e77a22
Commit
16e77a22
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#96 Tester, mangler én test.
parent
2cc92cd4
No related branches found
Branches containing commit
No related tags found
1 merge request
!57
#96 Telefonliste & Fiks til høyde på tabeller (rundt oppløsning)
Pipeline
#83622
failed
5 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_module_phonebook.py
+146
-0
146 additions, 0 deletions
test/test_module_phonebook.py
with
146 additions
and
0 deletions
test/test_module_phonebook.py
0 → 100644
+
146
−
0
View file @
16e77a22
"""
Test module_phonebook.py.
"""
import
unittest
from
PySide2.QtGui
import
qApp
,
QKeySequence
from
PySide2.QtCore
import
Qt
,
QTimer
from
PySide2.QtTest
import
QTest
from
PySide2.QtWidgets
import
QApplication
,
QCheckBox
,
QPushButton
from
soitool.soi
import
SOI
from
soitool.modules.module_phonebook
import
(
PhonebookModule
,
ColumnsChoicePopup
,
)
if
isinstance
(
qApp
,
type
(
None
)):
app
=
QApplication
([])
else
:
app
=
qApp
class
TestPhonebokkModule
(
unittest
.
TestCase
):
"""
TestCase for plane PhonebookModul.
"""
def
setUp
(
self
):
"""
Prepare a plane PhonebookModule.
"""
self
.
phonebook
=
PhonebookModule
()
self
.
phonebook
.
show
()
def
test_header
(
self
):
"""
Test header is correct.
"""
self
.
assertEqual
(
self
.
phonebook
.
header
.
text
(),
"
Telefonliste
"
)
def
test_type_table
(
self
):
"""
Test able to type in table and resize to content.
"""
rambo_quote
=
"
Live for nothing or die for something.
"
self
.
phonebook
.
table
.
setCurrentCell
(
1
,
0
)
QTest
.
keyClicks
(
self
.
phonebook
.
table
,
rambo_quote
)
print
(
self
.
phonebook
.
table
.
currentItem
().
text
())
# TODO
def
test_popup
(
self
):
"""
Test popup is shown and i able to edit columns.
"""
old_column_count
=
visible_columns_in
(
self
.
phonebook
.
table
)
def
popup_action
():
popup
=
app
.
activeModalWidget
().
layout
()
for
item_index
in
range
(
popup
.
count
()):
current_item
=
popup
.
itemAt
(
item_index
).
widget
()
if
(
isinstance
(
current_item
,
QCheckBox
)
and
current_item
.
text
()
==
"
E-post
"
):
current_item
.
setChecked
(
True
)
elif
isinstance
(
current_item
,
QPushButton
):
QTest
.
mouseClick
(
current_item
,
Qt
.
LeftButton
)
QTimer
.
singleShot
(
0
,
popup_action
)
QTest
.
keySequence
(
self
.
phonebook
,
QKeySequence
(
Qt
.
ControlModifier
+
Qt
.
Key_R
)
)
new_column_count
=
visible_columns_in
(
self
.
phonebook
.
table
)
self
.
assertEqual
(
new_column_count
,
old_column_count
+
1
)
def
test_add_row
(
self
):
"""
Test adding row.
"""
old_row_count
=
self
.
phonebook
.
table
.
rowCount
()
QTest
.
keySequence
(
self
.
phonebook
,
QKeySequence
(
Qt
.
ControlModifier
+
Qt
.
Key_Plus
)
)
new_row_count
=
self
.
phonebook
.
table
.
rowCount
()
self
.
assertEqual
(
new_row_count
,
old_row_count
+
1
)
def
test_remove_row
(
self
):
"""
Test removing row.
"""
self
.
phonebook
.
table
.
setRowCount
(
self
.
phonebook
.
table
.
rowCount
()
+
1
)
old_row_count
=
self
.
phonebook
.
table
.
rowCount
()
self
.
phonebook
.
table
.
setCurrentCell
(
1
,
0
)
QTest
.
keySequence
(
self
.
phonebook
,
QKeySequence
(
Qt
.
ControlModifier
+
Qt
.
Key_Minus
),
)
new_row_count
=
self
.
phonebook
.
table
.
rowCount
()
self
.
assertEqual
(
new_row_count
,
old_row_count
-
1
)
def
test_add_to_soi_smoke_test
(
self
):
"""
Test that can add to SOI sccessfully.
"""
soi
=
SOI
()
test_name
=
"
Test name
"
soi
.
add_module
(
test_name
,
self
.
phonebook
,
False
)
self
.
assertTrue
(
soi
.
module_name_taken
(
test_name
))
class
TestPhonebookModuleWithDataParameter
(
unittest
.
TestCase
):
"""
TestCase for PhoneBook with content preset.
"""
def
setUp
(
self
):
"""
Prepare a phonebook with preloaded content.
"""
self
.
data
=
{
"
Funksjon
"
:
[
"
Colonel Sam
"
,
"
Rambo
"
,
""
],
"
E-post
"
:
[
"
sam@usarmy.com
"
,
"
muscle@guns.com
"
,
""
],
}
self
.
phonebook
=
PhonebookModule
(
data
=
self
.
data
)
self
.
phonebook
.
show
()
def
test_column_count
(
self
):
"""
Test number of visible columns is correct.
"""
self
.
assertEqual
(
len
(
self
.
data
),
visible_columns_in
(
self
.
phonebook
.
table
)
)
def
test_content
(
self
):
"""
Test content is loaded correctly.
"""
for
column_index
in
range
(
self
.
phonebook
.
table
.
columnCount
()):
self
.
phonebook
.
table
.
setCurrentCell
(
0
,
column_index
)
column_header
=
self
.
phonebook
.
table
.
currentItem
().
text
()
if
not
self
.
phonebook
.
table
.
isColumnHidden
(
column_index
):
for
row_index
in
range
(
1
,
self
.
phonebook
.
table
.
rowCount
()):
self
.
phonebook
.
table
.
setCurrentCell
(
row_index
,
column_index
)
current_text
=
self
.
phonebook
.
table
.
currentItem
().
text
()
self
.
assertEqual
(
current_text
,
self
.
data
[
column_header
][
row_index
-
1
]
)
def
visible_columns_in
(
table
):
"""
Count number of visible columns in a table.
Parameters
----------
table : QTableWidget
The table to count visible columns in.
Returns
-------
counter : int
Number of visible columns in table.
"""
counter
=
0
for
column_index
in
range
(
table
.
columnCount
()):
if
not
table
.
isColumnHidden
(
column_index
):
counter
+=
1
return
counter
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment