Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dnfdaemon
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
manatools
dnfdaemon
Commits
d564c238
Commit
d564c238
authored
Oct 30, 2017
by
Eduard Čuba
Committed by
Neal Gompa (ニール・ゴンパ)
Jun 27, 2018
Browse files
Options
Downloads
Patches
Plain Diff
[tests]: use SWDB instead of YumDB and GroupPersistor
parent
7392dfc2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/support.py
+21
-62
21 additions, 62 deletions
test/support.py
with
21 additions
and
62 deletions
test/support.py
+
21
−
62
View file @
d564c238
...
@@ -56,17 +56,18 @@ LOCAL_RPM = os.path.join(repo_dir(), 'local-pkg-1.0-1.fc22.noarch.rpm')
...
@@ -56,17 +56,18 @@ LOCAL_RPM = os.path.join(repo_dir(), 'local-pkg-1.0-1.fc22.noarch.rpm')
# mock objects
# mock objects
def
mock_comps
(
seed_persistor
):
def
mock_comps
(
history
,
seed_persistor
):
comps
=
dnf
.
comps
.
Comps
()
comps
=
dnf
.
comps
.
Comps
()
comps
.
add_from_xml_filename
(
COMPS_PATH
)
comps
.
_
add_from_xml_filename
(
COMPS_PATH
)
persistor
=
MockGroupPersistor
()
persistor
=
history
.
group
if
seed_persistor
:
if
seed_persistor
:
p_som
=
persistor
.
group
(
'
inst-grp
'
)
name
=
'
inst-grp
'
p_som
.
pkg_types
=
dnf
.
comps
.
MANDATORY
pkg_types
=
dnf
.
comps
.
MANDATORY
p_som
.
full_list
.
extend
((
'
foo
'
,
'
bar
'
))
p_pep
=
persistor
.
new_group
(
name
,
name
,
name
,
False
,
pkg_types
)
persistor
.
add_group
(
p_pep
)
return
comps
,
persistor
p_pep
.
add_package
([
'
foo
'
,
'
bar
'
])
return
comps
class
_BaseStubMixin
(
object
):
class
_BaseStubMixin
(
object
):
...
@@ -88,7 +89,7 @@ class _BaseStubMixin(object):
...
@@ -88,7 +89,7 @@ class _BaseStubMixin(object):
self
.
_conf
=
FakeConf
()
self
.
_conf
=
FakeConf
()
self
.
_persistor
=
FakePersistor
()
self
.
_persistor
=
FakePersistor
()
self
.
_
yumdb
=
MockYumDB
()
self
.
_
history
=
None
self
.
ds_callback
=
mock
.
Mock
()
self
.
ds_callback
=
mock
.
Mock
()
@property
@property
...
@@ -97,8 +98,14 @@ class _BaseStubMixin(object):
...
@@ -97,8 +98,14 @@ class _BaseStubMixin(object):
return
self
.
_sack
return
self
.
_sack
return
self
.
init_sack
()
return
self
.
init_sack
()
def
_activate_group_persistor
(
self
):
@property
return
MockGroupPersistor
()
def
history
(
self
):
if
self
.
_history
:
return
self
.
_history
else
:
self
.
_history
=
super
(
_BaseStubMixin
,
self
).
history
self
.
_history
.
reset_db
()
return
self
.
_history
def
activate_persistor
(
self
):
def
activate_persistor
(
self
):
pass
pass
...
@@ -118,44 +125,13 @@ class _BaseStubMixin(object):
...
@@ -118,44 +125,13 @@ class _BaseStubMixin(object):
pass
pass
def
read_mock_comps
(
self
,
seed_persistor
=
True
):
def
read_mock_comps
(
self
,
seed_persistor
=
True
):
self
.
_comps
,
self
.
group_persistor
=
mock_comps
(
seed_persistor
)
self
.
_comps
=
mock_comps
(
self
.
history
,
seed_persistor
)
return
self
.
_comps
return
self
.
_comps
def
read_all_repos
(
self
):
def
read_all_repos
(
self
):
pass
pass
class
HistoryStub
(
dnf
.
yum
.
history
.
YumHistory
):
"""
Stub of dnf.yum.history.YumHistory for easier testing.
"""
def
__init__
(
self
):
"""
Initialize a stub instance.
"""
self
.
old_data_pkgs
=
{}
def
_old_data_pkgs
(
self
,
tid
,
sort
=
True
):
"""
Get packages of a transaction.
"""
if
sort
:
raise
NotImplementedError
(
'
sorting not implemented yet
'
)
return
self
.
old_data_pkgs
.
get
(
tid
,
())[:]
def
close
(
self
):
"""
Close the history.
"""
pass
def
old
(
self
,
tids
=
[],
limit
=
None
,
*
_args
,
**
_kwargs
):
"""
Get transactions with given IDs.
"""
create
=
lambda
tid
:
dnf
.
yum
.
history
.
YumHistoryTransaction
(
self
,
(
int
(
tid
),
0
,
'
0:685cc4ac4ce31b9190df1604a96a3c62a3100c35
'
,
1
,
'
1:685cc4ac4ce31b9190df1604a96a3c62a3100c36
'
,
0
,
0
))
sorted_all_tids
=
sorted
(
self
.
old_data_pkgs
.
keys
(),
reverse
=
True
)
trxs
=
(
create
(
tid
)
for
tid
in
tids
or
sorted_all_tids
if
tid
in
self
.
old_data_pkgs
)
limited
=
trxs
if
limit
is
None
else
itertools
.
islice
(
trxs
,
limit
)
return
tuple
(
limited
)
class
FakeAdvisoryRef
(
object
):
class
FakeAdvisoryRef
(
object
):
def
__init__
(
self
,
ref_id
,
ref_type
=
hawkey
.
REFERENCE_BUGZILLA
):
def
__init__
(
self
,
ref_id
,
ref_type
=
hawkey
.
REFERENCE_BUGZILLA
):
self
.
id
=
ref_id
self
.
id
=
ref_id
...
@@ -235,18 +211,6 @@ def mock_sack(*extra_repos):
...
@@ -235,18 +211,6 @@ def mock_sack(*extra_repos):
return
MockBase
(
*
extra_repos
).
sack
return
MockBase
(
*
extra_repos
).
sack
class
MockYumDB
(
mock
.
Mock
):
def
__init__
(
self
):
super
(
mock
.
Mock
,
self
).
__init__
()
self
.
db
=
{}
def
get_package
(
self
,
po
):
return
self
.
db
.
setdefault
(
str
(
po
),
mock
.
Mock
())
def
assertLength
(
self
,
length
):
assert
(
len
(
self
.
db
)
==
length
)
# mock object taken from testbase.py in yum/test:
# mock object taken from testbase.py in yum/test:
class
FakeConf
(
object
):
class
FakeConf
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -286,6 +250,7 @@ class FakeConf(object):
...
@@ -286,6 +250,7 @@ class FakeConf(object):
self
.
showdupesfromrepos
=
False
self
.
showdupesfromrepos
=
False
self
.
tsflags
=
[]
self
.
tsflags
=
[]
self
.
verbose
=
False
self
.
verbose
=
False
self
.
transformdb
=
False
self
.
yumvar
=
{
'
releasever
'
:
'
Fedora69
'
}
self
.
yumvar
=
{
'
releasever
'
:
'
Fedora69
'
}
def
iterkeys
(
self
):
def
iterkeys
(
self
):
...
@@ -304,12 +269,6 @@ class FakePersistor(object):
...
@@ -304,12 +269,6 @@ class FakePersistor(object):
def
since_last_makecache
(
self
):
def
since_last_makecache
(
self
):
return
None
return
None
class
MockGroupPersistor
(
dnf
.
persistor
.
GroupPersistor
):
"""
Empty persistor that doesn
'
t need any I/O.
"""
def
__init__
(
self
):
self
.
db
=
self
.
_empty_db
()
# test cases
# test cases
...
...
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