Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
1798bbc7
Commit
1798bbc7
authored
8 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Migration to pytest
parent
4f254bd2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sakia/tests/conftest.py
+63
-0
63 additions, 0 deletions
src/sakia/tests/conftest.py
with
63 additions
and
0 deletions
src/sakia/tests/conftest.py
0 → 100644
+
63
−
0
View file @
1798bbc7
import
pytest
import
asyncio
import
quamash
import
sqlite3
from
duniterpy.documents
import
BlockUID
from
sakia.data.repositories.meta
import
SakiaDatabase
_application_
=
[]
@pytest.yield_fixture
()
def
event_loop
():
qapplication
=
get_application
()
loop
=
quamash
.
QSelectorEventLoop
(
qapplication
)
exceptions
=
[]
loop
.
set_exception_handler
(
lambda
l
,
c
:
unitttest_exception_handler
(
exceptions
,
l
,
c
))
yield
loop
try
:
loop
.
close
()
finally
:
asyncio
.
set_event_loop
(
None
)
for
exc
in
exceptions
:
raise
exc
@pytest.fixture
()
def
meta_repo
():
sqlite3
.
register_adapter
(
BlockUID
,
str
)
sqlite3
.
register_adapter
(
bool
,
int
)
sqlite3
.
register_converter
(
"
BOOLEAN
"
,
lambda
v
:
bool
(
int
(
v
)))
meta_repo
=
SakiaDatabase
(
sqlite3
.
connect
(
"
:memory:
"
,
detect_types
=
sqlite3
.
PARSE_DECLTYPES
))
meta_repo
.
prepare
()
meta_repo
.
upgrade_database
()
return
meta_repo
def
unitttest_exception_handler
(
exceptions
,
loop
,
context
):
"""
An exception handler which exists the program if the exception
was not catch
:param loop: the asyncio loop
:param context: the exception context
"""
if
'
exception
'
in
context
:
exception
=
context
[
'
exception
'
]
else
:
exception
=
BaseException
(
context
[
'
message
'
])
exceptions
.
append
(
exception
)
def
get_application
():
"""
Get the singleton QApplication
"""
from
quamash
import
QApplication
if
not
len
(
_application_
):
application
=
QApplication
.
instance
()
if
not
application
:
import
sys
application
=
QApplication
(
sys
.
argv
)
_application_
.
append
(
application
)
return
_application_
[
0
]
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