Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar GTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
briar
Briar GTK
Merge requests
!36
Add tests for Application
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add tests for Application
tests
into
master
Overview
0
Commits
1
Pipelines
2
Changes
2
Merged
Nico
requested to merge
tests
into
master
5 years ago
Overview
0
Commits
1
Pipelines
2
Changes
2
Expand
0
0
Merge request reports
Compare
master
version 1
8c1581ba
5 years ago
master (base)
and
latest version
latest version
72df97fa
1 commit,
5 years ago
version 1
8c1581ba
1 commit,
5 years ago
2 files
+
98
−
37
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
briar-gtk/tests/briar_gtk/test_application.py
+
98
−
30
Options
@@ -2,55 +2,123 @@
@@ -2,55 +2,123 @@
# SPDX-License-Identifier: AGPL-3.0-only
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
# License-Filename: LICENSE.md
from
unittest.mock
import
Mock
import
pytest
import
pytest
from
briar_wrapper.api
import
Api
from
briar_gtk.application
import
Application
from
briar_gtk.application
import
Application
from
briar_gtk.define
import
APPLICATION_NAME
,
APPLICATION_STYLING_PATH
from
briar_gtk.define
import
BRIAR_HEADLESS_JAR
from
briar_gtk.window
import
Window
MODULE
=
"
briar_gtk.application.%s
"
def
test_application_actions_at_init
(
mocker
):
application_actions_mock
=
mocker
.
patch
(
MODULE
%
"
ApplicationActions
"
)
application
=
Application
()
application_actions_mock
.
assert_called_once_with
(
application
)
def
test_application_name_at_init
(
mocker
):
application_name_mock
=
mocker
.
patch
(
MODULE
%
"
GLib.set_application_name
"
)
prgname_mock
=
mocker
.
patch
(
MODULE
%
"
GLib.set_prgname
"
)
application
=
Application
()
application_name_mock
.
assert_called_once_with
(
"
Briar
"
)
prgname_mock
.
assert_called_once_with
(
"
Briar
"
)
def
test_api_at_startup
(
mocker
):
api_mock
=
mocker
.
patch
(
MODULE
%
"
Api
"
)
Application
().
do_startup
()
api_mock
.
assert_called_once_with
(
"
/app/briar/briar-headless.jar
"
)
def
test_css_provider_at_startup
(
mocker
):
css_provider_mock
=
mocker
.
patch
(
MODULE
%
"
Gtk.CssProvider
"
)
Application
().
do_startup
()
css_provider_mock
.
assert_called_once
()
def
test_handy_at_startup
(
mocker
):
handy_mock
=
mocker
.
patch
(
MODULE
%
"
Handy.init
"
)
Application
().
do_startup
()
handy_mock
.
assert_called_once
()
def
test_startup_at_startup
(
mocker
):
do_startup_mock
=
mocker
.
patch
(
MODULE
%
"
Gtk.Application.do_startup
"
)
application
=
Application
()
application
.
do_startup
()
def
test_do_startup
(
mocker
):
do_startup_mock
.
assert_called_once_with
(
application
)
do_startup_mock
=
mocker
.
patch
(
"
gi.repository.Gtk.Application.do_startup
"
)
_setup_styling_mock
=
mocker
.
patch
(
"
briar_gtk.application.Application._setup_styling
"
)
def
test_style_context_at_startup
(
mocker
):
_setup_api_mock
=
mocker
.
patch
(
style_context_mock
=
mocker
.
patch
(
MODULE
%
"
Gtk.StyleContext
"
)
"
briar_gtk.application.Application._setup_api
"
)
Application
().
do_startup
()
Application
().
do_startup
()
do_startup_mock
.
assert_called_once
()
style_context_mock
.
assert_called_once
()
_setup_styling_mock
.
assert_called_once_with
(
APPLICATION_STYLING_PATH
)
_setup_api_mock
.
assert_called_once
()
def
test_do_activate
(
mocker
):
def
test_window_at_activate
(
mocker
):
_setup_window_mock
=
mocker
.
patch
(
window_mock
=
mocker
.
patch
(
MODULE
%
"
Window
"
)
"
briar_gtk.application.Application._setup_window
"
)
Application
().
do_activate
()
Application
().
do_activate
()
_setup_
window_mock
.
assert_called_once
()
window_mock
.
assert_called_once
()
def
test_do_shutdown
(
mocker
):
def
test_already_window_at_activate
(
mocker
):
api_mock
=
mocker
.
patch
(
"
briar_wrapper.api.Api
"
)
gtk_window_mock
=
mocker
.
patch
(
MODULE
%
"
Window
"
)
api_stop_mock
=
mocker
.
patch
(
"
briar_wrapper.api.Api.stop
"
)
window_mock
=
mocker
.
MagicMock
()
window_mock
=
mocker
.
patch
(
"
briar_gtk.window.Window
"
)
window_hide_mock
=
mocker
.
patch
(
"
briar_gtk.window.Window.hide
"
)
application
=
Application
()
do_shutdown_mock
=
mocker
.
patch
(
application
.
window
=
window_mock
"
gi.repository.Gio.Application.do_shutdown
"
)
application
.
do_activate
()
window_mock
.
present
.
assert_called_once
()
assert
gtk_window_mock
.
called
is
False
def
test_api_stop_at_shutdown
(
mocker
):
api_mock
=
mocker
.
patch
(
MODULE
%
"
Api
"
)
application
=
Application
()
application
=
Application
()
application
.
api
=
api_mock
application
.
api
=
api_mock
application
.
window
=
mocker
.
MagicMock
()
application
.
do_shutdown
()
api_mock
.
stop
.
assert_called_once
()
def
test_window_hide_at_shutdown
(
mocker
):
window_mock
=
mocker
.
patch
(
MODULE
%
"
Window
"
)
application
=
Application
()
application
.
api
=
mocker
.
MagicMock
()
application
.
window
=
window_mock
application
.
window
=
window_mock
application
.
do_shutdown
()
application
.
do_shutdown
()
api_stop_mock
.
assert_called_once
()
window_mock
.
hide
.
assert_called_once
()
window_hide_mock
.
assert_called_once
()
do_shutdown_mock
.
assert_called_once
()
@pytest.fixture
(
autouse
=
True
)
def
gi_dependencies
(
mocker
):
gi_dependencies
=
(
'
Gdk
'
,
'
Gio
'
,
'
GLib
'
,
'
Gtk
'
,
'
Handy
'
)
for
dependency
in
gi_dependencies
:
mocker
.
patch
(
MODULE
%
dependency
)
Loading