Skip to content

Commit

Permalink
🪲 Prevent ipynb conversion unit tests from interacting with the font …
Browse files Browse the repository at this point in the history
…manager. These are not integration tests ! There is no QApplication setup that allows you to retrieve theme information.
  • Loading branch information
vanyle committed Dec 20, 2021
1 parent df51985 commit 41b7f17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions opencodeblocks/scene/from_ipynb_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
from opencodeblocks.graphics.pyeditor import POINT_SIZE


def ipynb_to_ipyg(data: OrderedDict) -> OrderedDict:
"""Convert ipynb data (ipynb file, as ordered dict) into ipyg data (ipyg, as ordered dict)"""
def ipynb_to_ipyg(data: OrderedDict, use_theme_font: bool = True) -> OrderedDict:
"""
Convert ipynb data (ipynb file, as ordered dict) into ipyg data (ipyg, as ordered dict)
- use_theme_font: should the height of the blocks be computed based on the current
font selected.
"""

blocks_data: List[OrderedDict] = get_blocks_data(data)
blocks_data: List[OrderedDict] = get_blocks_data(data, use_theme_font)
edges_data: List[OrderedDict] = get_edges_data(blocks_data)

return {
Expand All @@ -21,7 +25,9 @@ def ipynb_to_ipyg(data: OrderedDict) -> OrderedDict:
}


def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:
def get_blocks_data(
data: OrderedDict, use_theme_font: bool = True
) -> List[OrderedDict]:
"""
Get the blocks corresponding to a ipynb file,
Returns them in the ipyg ordered dict format
Expand All @@ -32,7 +38,8 @@ def get_blocks_data(data: OrderedDict) -> List[OrderedDict]:

# Get the font metrics to determine the size fo the blocks
font = QFont()
font.setFamily(theme_manager().recommended_font_family)
if use_theme_font:
font.setFamily(theme_manager().recommended_font_family)
font.setFixedPitch(True)
font.setPointSize(POINT_SIZE)
fontmetrics = QFontMetrics(font)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/scene/test_ipynb_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestIpynbConversion:

def test_empty_data(self, mocker: MockerFixture):
"""should return empty ipyg graph for empty data."""
check.equal(ipynb_to_ipyg({}), {"blocks": [], "edges": []})
check.equal(ipynb_to_ipyg({}, False), {"blocks": [], "edges": []})

def test_empty_notebook_data(self, mocker: MockerFixture):
"""should return expected graph for a real empty notebook data."""
Expand Down Expand Up @@ -56,7 +56,7 @@ def real_notebook_conversion_is_coherent(file_path: str):
file_path: the path to a .ipynb file
"""
ipynb_data = load_json(file_path)
ipyg_data = ipynb_to_ipyg(ipynb_data)
ipyg_data = ipynb_to_ipyg(ipynb_data, False)
check_conversion_coherence(ipynb_data, ipyg_data)


Expand Down

0 comments on commit 41b7f17

Please sign in to comment.