-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move duplicated
source_to_table
to utils
- Loading branch information
1 parent
bed427d
commit 993519f
Showing
4 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
|
||
if TYPE_CHECKING: | ||
from tomlkit.items import Table | ||
|
||
from poetry.config.source import Source | ||
|
||
|
||
def source_to_table(source: Source) -> Table: | ||
from tomlkit import nl | ||
from tomlkit import table | ||
|
||
source_table: Table = table() | ||
for key, value in source.to_dict().items(): | ||
source_table.add(key, value) | ||
source_table.add(nl()) | ||
return source_table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from tomlkit.container import Container | ||
from tomlkit.items import Table | ||
from tomlkit.items import Trivia | ||
|
||
from poetry.config.source import Source | ||
from poetry.utils.source import source_to_table | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"source,table_body", | ||
[ | ||
( | ||
Source("foo", "https://example.com"), | ||
{ | ||
"default": False, | ||
"name": "foo", | ||
"secondary": False, | ||
"url": "https://example.com", | ||
}, | ||
), | ||
( | ||
Source("bar", "https://example.com/bar", True, True), | ||
{ | ||
"default": True, | ||
"name": "bar", | ||
"secondary": True, | ||
"url": "https://example.com/bar", | ||
}, | ||
), | ||
], | ||
) | ||
def test_source_to_table(source: Source, table_body: dict[str, str | bool]): | ||
table = Table(Container(), Trivia(), False) | ||
table._value = table_body | ||
|
||
assert source_to_table(source) == table |