Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tom Pillot
Thymio Game
Commits
d947a171
Commit
d947a171
authored
Jun 29, 2020
by
Tom Pillot
Browse files
Add tests for the team chooser window
parent
a72da914
Changes
7
Hide whitespace changes
Inline
Side-by-side
detector.py
→
game/
detector.py
View file @
d947a171
File moved
scoreboard.py
→
game/
scoreboard.py
View file @
d947a171
from
PyQt5
import
QtWidgets
as
qtw
from
game.scoreboard_ui
import
ScoreWindowUi
from
PyQt5
import
QtCore
as
qtc
from
PyQt5
import
QtGui
as
qtg
from
scoreboard_ui
import
ScoreWindowUi
DURATION
=
30
DURATION
=
30
...
...
scoreboard_ui.py
→
game/
scoreboard_ui.py
View file @
d947a171
File moved
team_chooser.py
→
game/
team_chooser.py
View file @
d947a171
import
sys
from
PyQt5
import
QtWidgets
as
qtw
from
PyQt5
import
QtCore
as
qtc
from
PyQt5
import
QtCore
as
qtc
from
PyQt5
import
QtGui
as
qtg
from
PyQt5
import
QtGui
as
qtg
from
detector
import
Detector
from
game.detector
import
Detector
from
team_chooser_ui
import
TeamWindowUi
from
game.team_chooser_ui
import
TeamWindowUi
team_colors
=
{
1
:
"#FE3200"
,
2
:
"#FE6500"
,
3
:
"#FE9800"
,
4
:
"#FECB00"
,
5
:
"#FEFE00"
,
6
:
"#CBFE00"
,
24
:
"#98FE00"
,
25
:
"#65FE00"
,
26
:
"#32FE00"
,
27
:
"#00FE00"
,
28
:
"00FE32"
,
29
:
"#00FE65"
,
30
:
"#00FE98"
,
48
:
"#00FECB"
,
49
:
"#00FEFE"
,
50
:
"#00CBFE"
,
51
:
"#0098FE"
,
52
:
"#0065FE"
,
53
:
"#0032FE"
,
54
:
"#0000FE"
,
72
:
"#3200FE"
,
73
:
"#6500FE"
,
74
:
"#A100FE"
,
75
:
"#D400FE"
,
76
:
"#FE00F6"
,
77
:
"#FF00C3"
,
78
:
"#FE008F"
,
96
:
"#FE005D"
,
97
:
"#FE002A"
,
98
:
"#474747"
,
99
:
"#8C8C8C"
,
100
:
"#643030"
,
101
:
"#9A6565"
,
102
:
"#BC9F9F"
}
class
TeamWindow
(
TeamWindowUi
):
class
TeamWindow
(
TeamWindowUi
):
NAME
,
TAG
=
range
(
2
)
NAME
,
TAG
=
range
(
2
)
STATUS_TIME
=
5000
STATUS_TIME
=
5000
team_colors
=
{
1
:
"#FE3200"
,
2
:
"#FE6500"
,
3
:
"#FE9800"
,
4
:
"#FECB00"
,
5
:
"#FEFE00"
,
6
:
"#CBFE00"
,
24
:
"#98FE00"
,
25
:
"#65FE00"
,
26
:
"#32FE00"
,
27
:
"#00FE00"
,
28
:
"00FE32"
,
29
:
"#00FE65"
,
30
:
"#00FE98"
,
48
:
"#00FECB"
,
49
:
"#00FEFE"
,
50
:
"#00CBFE"
,
51
:
"#0098FE"
,
52
:
"#0065FE"
,
53
:
"#0032FE"
,
54
:
"#0000FE"
,
72
:
"#3200FE"
,
73
:
"#6500FE"
,
74
:
"#A100FE"
,
75
:
"#D400FE"
,
76
:
"#FE00F6"
,
77
:
"#FF00C3"
,
78
:
"#FE008F"
,
96
:
"#FE005D"
,
97
:
"#FE002A"
,
98
:
"#474747"
,
99
:
"#8C8C8C"
,
100
:
"#643030"
,
101
:
"#9A6565"
,
102
:
"#BC9F9F"
}
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
...
@@ -31,7 +28,7 @@ class TeamWindow(TeamWindowUi):
...
@@ -31,7 +28,7 @@ class TeamWindow(TeamWindowUi):
def
set_label_color
(
self
,
tag_id
):
def
set_label_color
(
self
,
tag_id
):
try
:
try
:
color_hex
=
team_colors
[
tag_id
]
color_hex
=
self
.
team_colors
[
tag_id
]
self
.
tag_label
.
setStyleSheet
(
f
"color: black; background-color:
{
color_hex
}
"
)
self
.
tag_label
.
setStyleSheet
(
f
"color: black; background-color:
{
color_hex
}
"
)
return
True
return
True
except
KeyError
:
except
KeyError
:
...
@@ -53,7 +50,7 @@ class TeamWindow(TeamWindowUi):
...
@@ -53,7 +50,7 @@ class TeamWindow(TeamWindowUi):
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
NAME
),
name
)
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
NAME
),
name
)
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
TAG
),
tag_id
)
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
TAG
),
tag_id
)
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
TAG
),
self
.
table_model
.
setData
(
self
.
table_model
.
index
(
0
,
self
.
TAG
),
qtg
.
QBrush
(
qtg
.
QColor
(
team_colors
[
tag_id
])),
qtc
.
Qt
.
BackgroundRole
)
qtg
.
QBrush
(
qtg
.
QColor
(
self
.
team_colors
[
tag_id
])),
qtc
.
Qt
.
BackgroundRole
)
# Delete the last input
# Delete the last input
self
.
tag_label
.
setText
(
""
)
self
.
tag_label
.
setText
(
""
)
self
.
tag_label
.
setStyleSheet
(
""
)
self
.
tag_label
.
setStyleSheet
(
""
)
...
...
team_chooser_ui.py
→
game/
team_chooser_ui.py
View file @
d947a171
File moved
main.py
View file @
d947a171
import
sys
import
sys
from
PyQt5
import
QtWidgets
as
qtw
from
PyQt5
import
QtWidgets
as
qtw
from
team_chooser
import
TeamWindow
from
game.
team_chooser
import
TeamWindow
from
scoreboard
import
ScoreWindow
from
game.
scoreboard
import
ScoreWindow
class
MainWindow
(
qtw
.
QWidget
):
class
MainWindow
(
qtw
.
QWidget
):
...
...
tests/test_team_chooser.py
0 → 100644
View file @
d947a171
import
unittest
,
sys
from
PyQt5
import
QtWidgets
as
qtw
from
game.team_chooser
import
TeamWindow
app
=
qtw
.
QApplication
(
sys
.
argv
)
team_window
=
TeamWindow
()
class
TestTeamChooser
(
unittest
.
TestCase
):
def
test_add_team
(
self
):
for
tag_id
in
team_window
.
team_colors
.
keys
():
tag_str
=
str
(
tag_id
)
name
=
"test"
+
str
(
tag_id
)
team_window
.
name_input
.
setText
(
name
)
team_window
.
tag_label
.
setText
(
tag_str
)
team_window
.
add_button
.
click
()
table_name
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
0
,
team_window
.
NAME
))
table_tag_id
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
0
,
team_window
.
TAG
))
self
.
assertEqual
(
name
,
table_name
)
self
.
assertEqual
(
tag_id
,
table_tag_id
)
def
test_edit_team
(
self
):
row
=
4
name
,
tag_id
=
select_row
(
row
)
team_window
.
edit_button
.
click
()
self
.
assertEqual
(
name
,
team_window
.
name_input
.
text
())
self
.
assertEqual
(
tag_id
,
int
(
team_window
.
tag_label
.
text
()))
def
test_delete_team
(
self
):
row
=
9
name
,
tag_id
=
select_row
(
row
)
team_window
.
delete_button
.
click
()
name_after_delete
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
row
,
team_window
.
NAME
))
tag_id_after_delete
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
row
,
team_window
.
TAG
))
self
.
assertNotEqual
(
name
,
name_after_delete
)
self
.
assertNotEqual
(
tag_id
,
tag_id_after_delete
)
def
test_is_valid
(
self
):
self
.
assertFalse
(
team_window
.
is_valid
(
""
,
"78"
))
self
.
assertFalse
(
team_window
.
is_valid
(
"test"
,
""
))
self
.
assertTrue
(
team_window
.
is_valid
(
"test"
,
"98"
))
def
select_row
(
row
):
team_window
.
table_view
.
selectRow
(
row
)
selected
=
team_window
.
table_view
.
selectedIndexes
()[
0
]
name
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
selected
.
row
(),
team_window
.
NAME
))
tag_id
=
team_window
.
table_model
.
data
(
team_window
.
table_model
.
index
(
selected
.
row
(),
team_window
.
TAG
))
return
name
,
tag_id
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment