Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tuneit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
tuneit
Commits
5f43805a
Commit
5f43805a
authored
Feb 03, 2025
by
Anton Palgunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests
parent
49388b80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
2 deletions
+83
-2
.gitignore
.gitignore
+3
-2
pytest.ini
pytest.ini
+6
-0
main.py
src/shop/main.py
+2
-0
test_main.py
src/shop/test_main.py
+72
-0
No files found.
.gitignore
View file @
5f43805a
...
...
@@ -12,4 +12,5 @@
# meson
_build
subprojects/
\ No newline at end of file
subprojects/
__pycache__/
\ No newline at end of file
pytest.ini
0 → 100644
View file @
5f43805a
[pytest]
testpaths
=
src
markers
=
smoke:
mark
test
as
smoke
test
regression:
mark
test
as
regression
test
\ No newline at end of file
src/shop/main.py
View file @
5f43805a
...
...
@@ -408,6 +408,8 @@ def load_data(split_view, force_refresh=False, page=1):
start_idx
=
(
page
-
1
)
*
split_view
.
_per_page
end_idx
=
start_idx
+
split_view
.
_per_page
page_data
=
repos
[
start_idx
:
end_idx
]
print
(
f
"Page {page}: {len(page_data)} items"
)
# Если page_data меньше per_page, значит всё
if
len
(
page_data
)
<
split_view
.
_per_page
:
...
...
src/shop/test_main.py
0 → 100644
View file @
5f43805a
import
pytest
import
time
import
sys
import
os
from
unittest.mock
import
patch
,
MagicMock
# Ensure the shop module is in the Python path
sys
.
path
.
insert
(
0
,
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
)))
from
shop.main
import
retrieve_modules_full_list
,
load_from_cache
,
save_to_cache
,
fetch_repos_from_github
,
fetch_repos_from_gitlab
@patch
(
"shop.main.load_from_cache"
)
@patch
(
"shop.main.save_to_cache"
)
@patch
(
"shop.main.fetch_repos_from_github"
)
@patch
(
"shop.main.fetch_repos_from_gitlab"
)
@patch
(
"time.time"
,
return_value
=
1609459200
)
# Mock time to a fixed timestamp
def
test_retrieve_modules_full_list
(
mock_time
,
mock_fetch_gitlab
,
mock_fetch_github
,
mock_save_cache
,
mock_load_cache
):
# Mock cache data
mock_load_cache
.
return_value
=
(
None
,
0
)
# Mock GitHub response
mock_fetch_github
.
return_value
=
[
{
"name"
:
"tuneit-mod-example"
,
"owner"
:
{
"login"
:
"example"
},
"default_branch"
:
"main"
,
"stargazers_count"
:
10
,
"description"
:
"Example description"
,
"html_url"
:
"https://github.com/example/tuneit-mod-example"
,
"full_name"
:
"example/tuneit-mod-example"
}
]
# Mock GitLab response
mock_fetch_gitlab
.
return_value
=
[
{
"name"
:
"tuneit-mod-example"
,
"path_with_namespace"
:
"example/tuneit-mod-example"
,
"default_branch"
:
"main"
,
"star_count"
:
5
,
"description"
:
"Example description"
,
"web_url"
:
"https://gitlab.com/example/tuneit-mod-example"
}
]
# Mock parse_module_yaml to return a dummy module info
with
patch
(
"shop.main.parse_module_yaml"
,
return_value
=
[{
"name"
:
"Example Module"
,
"description"
:
"Example module description"
}]):
repos
=
retrieve_modules_full_list
(
force_refresh
=
True
,
initial_page
=
1
,
per_page
=
30
)
assert
len
(
repos
)
==
2
assert
repos
[
0
][
"source"
]
==
"github"
assert
repos
[
0
][
"repo_name"
]
==
"tuneit-mod-example"
assert
repos
[
0
][
"stars"
]
==
10
assert
repos
[
0
][
"module_yaml"
][
"name"
]
==
"Example Module"
assert
repos
[
1
][
"source"
]
==
"gitlab"
assert
repos
[
1
][
"repo_name"
]
==
"tuneit-mod-example"
assert
repos
[
1
][
"stars"
]
==
5
assert
repos
[
1
][
"module_yaml"
][
"name"
]
==
"Example Module"
mock_save_cache
.
assert_called_once
()
@patch
(
"shop.main.load_from_cache"
)
@patch
(
"time.time"
,
return_value
=
1609459200
)
# Mock time to a fixed timestamp
def
test_retrieve_modules_full_list_cache
(
mock_time
,
mock_load_cache
):
# Mock cache data
mock_load_cache
.
return_value
=
([{
"repo_name"
:
"cached-repo"
}],
1609455600
)
repos
=
retrieve_modules_full_list
(
force_refresh
=
False
,
initial_page
=
1
,
per_page
=
30
)
assert
len
(
repos
)
==
1
assert
repos
[
0
][
"repo_name"
]
==
"cached-repo"
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