Skip to content

[ENG-8223] Fix mfr unittests #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: feature/buff-worms
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
44e3f0f
ENG-7603 upgrade infra deps and another updates that is needed to be …
mkovalua May 30, 2025
e243c1f
[tool:pytest] is a way to work with python3.13
mkovalua Jun 3, 2025
3bab7d9
update requirements.txt to make it possible to run unittest tests , a…
mkovalua Jun 4, 2025
caaf0d2
fix bad for py3.13 async with await aiohttp.request -> to async with …
mkovalua Jun 4, 2025
e660d25
ContentEncodingError is removed for python3.13 -> replace with excep…
mkovalua Jun 4, 2025
d2f831e
fix for py3.13
mkovalua Jun 5, 2025
2b7f97e
Todo: for possible agent lib removal
mkovalua Jun 5, 2025
18c0522
fix wrong fixture call usage
mkovalua Jun 12, 2025
9586566
return markdown version with __version__ (it is string, maybe it is n…
mkovalua Jun 12, 2025
fd89244
return Image version with __version__ (it is string, maybe it is need…
mkovalua Jun 12, 2025
d572ebd
fix 0 index access error
mkovalua Jun 13, 2025
fb0d901
fix test_render_iso_not_utf16 body structure changings
mkovalua Jun 13, 2025
c8ebb09
fix AttributeError: '_PyDocXHTMLExporter' object has no attribute 'pa…
mkovalua Jun 13, 2025
e5ab0ab
fix AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
mkovalua Jun 13, 2025
79bb027
fix jinja2.exceptions.TemplateNotFound: basic (template_file looks t…
mkovalua Jun 13, 2025
af2f5c1
fix EscapeHtml.extendMarkdown() missing 1 required positional argume…
mkovalua Jun 13, 2025
3e50ae3
fix module 'PIL.Image' has no attribute 'VERSION
mkovalua Jun 13, 2025
abc3692
fix AttributeError: 'Dataset' object has no attribute 'value'
mkovalua Jun 13, 2025
7348c14
fix AttributeError: 'Series' object has no attribute 'iteritems'
mkovalua Jun 13, 2025
b7fd773
fix numpy.asscalar deprecation
mkovalua Jun 16, 2025
83f46b2
resolve RuntimeError: There is no current event loop in thread 'Main…
mkovalua Jun 18, 2025
45aaf82
fix test_render test, it looks html body was updated with another <tr…
mkovalua Jun 18, 2025
b66bb3e
fix xrld issue
sh-andriy Jun 18, 2025
6b05768
merge feature/buff-worms into fix-mfr-unittests
mkovalua Jun 18, 2025
b3b9bd6
Merge remote-tracking branch 'mkovalua/fix-mfr-unittests' into fix-mf…
sh-andriy Jun 18, 2025
5864da7
fix xrld issue
sh-andriy Jun 18, 2025
5d599bb
fix xrld issue
sh-andriy Jun 18, 2025
d4683eb
remain old test.docx file
mkovalua Jun 19, 2025
7a4e093
fix failing tests docx error
sh-andriy Jun 23, 2025
068e532
fix failing tests: extensions, server
sh-andriy Jun 23, 2025
fb26802
fix flake8 remarks to run tests
mkovalua Jun 23, 2025
b56392a
remove pydocx that is not used anymore
mkovalua Jun 24, 2025
a3c748e
remove pydocx from poetry that is not used anymore
mkovalua Jun 24, 2025
9c40252
infra: update mfr installation method
mkovalua Jun 24, 2025
3dbb78e
infra: try switching to implicit namespaces
mkovalua Jun 24, 2025
16871ee
infra: use egg_info
mkovalua Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ jobs:
run: poetry run flake8 .

- name: Build plugins
run: poetry run python setup.py develop
run: |
python3 setup.py egg_info
poetry run pip install .

- name: Run unit tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ COPY ./ /code/
ARG GIT_COMMIT=
ENV GIT_COMMIT=${GIT_COMMIT}

RUN poetry run python setup.py develop
RUN python3 setup.py egg_info
RUN python3 -m pip install .

EXPOSE 7778

Expand Down
28 changes: 14 additions & 14 deletions mfr/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExtensionError(PluginError):

__TYPE = 'extension'

def __init__(self, message, *args, extension: str='', **kwargs):
def __init__(self, message, *args, extension: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.extension = extension
self.attr_stack.append([self.__TYPE, {'extension': self.extension}])
Expand All @@ -59,7 +59,7 @@ class RendererError(ExtensionError):

__TYPE = 'renderer'

def __init__(self, message, *args, renderer_class: str='', **kwargs):
def __init__(self, message, *args, renderer_class: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.renderer_class = renderer_class
self.attr_stack.append([self.__TYPE, {'class': self.renderer_class}])
Expand All @@ -72,7 +72,7 @@ class ExporterError(ExtensionError):

__TYPE = 'exporter'

def __init__(self, message, *args, exporter_class: str='', **kwargs):
def __init__(self, message, *args, exporter_class: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.exporter_class = exporter_class
self.attr_stack.append([self.__TYPE, {'exporter_class': self.exporter_class}])
Expand All @@ -85,8 +85,8 @@ class SubprocessError(ExporterError):

__TYPE = 'subprocess'

def __init__(self, message, *args, code: int=500, process: str='', cmd: str='',
returncode: int=None, path: str='', **kwargs):
def __init__(self, message, *args, code: int = 500, process: str = '', cmd: str = '',
returncode: int = None, path: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.process = process
self.cmd = cmd
Expand All @@ -107,7 +107,7 @@ class ProviderError(PluginError):

__TYPE = 'provider'

def __init__(self, message, *args, provider: str='', **kwargs):
def __init__(self, message, *args, provider: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.provider = provider
self.attr_stack.append([self.__TYPE, {'provider': self.provider}])
Expand All @@ -120,7 +120,7 @@ class DownloadError(ProviderError):

__TYPE = 'download'

def __init__(self, message, *args, download_url: str='', response: str='', **kwargs):
def __init__(self, message, *args, download_url: str = '', response: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.download_url = download_url
self.response = response
Expand All @@ -137,7 +137,7 @@ class MetadataError(ProviderError):

__TYPE = 'metadata'

def __init__(self, message, *args, metadata_url: str='', response: str='', **kwargs):
def __init__(self, message, *args, metadata_url: str = '', response: str = '', **kwargs):
super().__init__(message, *args, **kwargs)
self.metadata_url = metadata_url
self.response = response
Expand All @@ -153,8 +153,8 @@ class TooBigToRenderError(ProviderError):

__TYPE = 'too_big_to_render'

def __init__(self, message, *args, requested_size: int=None, maximum_size: int=None,
code: int=400, **kwargs):
def __init__(self, message, *args, requested_size: int = None, maximum_size: int = None,
code: int = 400, **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.requested_size = requested_size
self.maximum_size = maximum_size
Expand All @@ -168,8 +168,8 @@ class DriverManagerError(PluginError):

__TYPE = 'drivermanager'

def __init__(self, message, *args, namespace: str='', name: str='', invoke_on_load: bool=None,
invoke_args: dict=None, **kwargs):
def __init__(self, message, *args, namespace: str = '', name: str = '', invoke_on_load: bool = None,
invoke_args: dict = None, **kwargs):
super().__init__(message, *args, **kwargs)

self.namespace = namespace
Expand All @@ -189,7 +189,7 @@ class MakeProviderError(DriverManagerError):
"""Thrown when MFR can't find an applicable provider class. This indicates programmer error,
so ``code`` defaults to ``500``."""

def __init__(self, message, *args, code: int=500, **kwargs):
def __init__(self, message, *args, code: int = 500, **kwargs):
super().__init__(message, *args, code=code, **kwargs)


Expand All @@ -201,7 +201,7 @@ class UnsupportedExtensionError(DriverManagerError):

__TYPE = 'unsupported_extension'

def __init__(self, *args, code: int=400, handler_type: str='', **kwargs):
def __init__(self, *args, code: int = 400, handler_type: str = '', **kwargs):
super().__init__(*args, code=code, **kwargs)

self.handler_type = handler_type
Expand Down
5 changes: 1 addition & 4 deletions mfr/core/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ async def log_analytics(request, metrics, is_error=False):
domain='private')

if (
keen_payload['handler']['type'] != 'render' or
file_metadata is None or
is_error or
not settings.KEEN_PUBLIC_LOG_VIEWS
keen_payload['handler']['type'] != 'render' or file_metadata is None or is_error or not settings.KEEN_PUBLIC_LOG_VIEWS
):
return

Expand Down
14 changes: 8 additions & 6 deletions mfr/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ def get_renderer_name(name: str) -> str:
# `ep_iterator` is an iterable object. Must convert it to a `list` for access.
# `list()` can only be called once because the iterator moves to the end after conversion.
ep = entry_points().select(group='mfr.renderers', name=name.lower())
ep_list = list(ep)

# Empty list indicates unsupported file type. Return '' and let `make_renderer()` handle it.
if len(ep) == 0:
if len(ep_list) == 0:
return ''

# If the file type is supported, there must be only one element in the list.
assert len(ep) == 1
return ep[0].value.split(":")[1].split('.')[0]
assert len(ep_list) == 1
return ep_list[0].value.split(":")[-1]


def get_exporter_name(name: str) -> str:
Expand All @@ -135,14 +136,15 @@ def get_exporter_name(name: str) -> str:
# `ep_iterator` is an iterable object. Must convert it to a `list` for access.
# `list()` can only be called once because the iterator moves to the end after conversion.
ep = entry_points().select(group='mfr.exporters', name=name.lower())
ep_list = list(ep)

# Empty list indicates unsupported export type. Return '' and let `make_exporter()` handle it.
if len(ep) == 0:
if len(ep_list) == 0:
return ''

# If the export type is supported, there must be only one element in the list.
assert len(ep) == 1
return ep[0].value.split(":")[1].split('.')[0]
assert len(ep_list) == 1
return ep_list[0].value.split(":")[-1]


def sizeof_fmt(num, suffix='B'):
Expand Down
6 changes: 3 additions & 3 deletions mfr/extensions/codepygments/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileTooLargeError(CodePygmentsRendererError):

__TYPE = 'codepygments_file_too_large'

def __init__(self, message, *args, code: int=400, file_size: int=None, max_size: int=None,
def __init__(self, message, *args, code: int = 400, file_size: int = None, max_size: int = None,
**kwargs):
super().__init__(message, *args, code=code, **kwargs)

Expand All @@ -33,8 +33,8 @@ class FileDecodingError(CodePygmentsRendererError):

__TYPE = 'codepygments_file_decoding'

def __init__(self, message, *args, code: int=400, original_exception: Exception=None,
category: str='', **kwargs):
def __init__(self, message, *args, code: int = 400, original_exception: Exception = None,
category: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)

self.category = category
Expand Down
4 changes: 2 additions & 2 deletions mfr/extensions/image/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class PillowImageError(ExporterError):

__TYPE = 'image_pillow'

def __init__(self, message, *args, export_format: str='', detected_format: str='',
original_exception: Exception=None, **kwargs):
def __init__(self, message, *args, export_format: str = '', detected_format: str = '',
original_exception: Exception = None, **kwargs):
super().__init__(message, *args, exporter_class='image', **kwargs)

self.export_format = export_format
Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/image/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def export(self):
'Unable to export the file as a {}, please check that the '
'file is a valid image.'.format(image_type),
export_format=image_type,
detected_format= self.detect_image_format(),
detected_format=self.detect_image_format(),
original_exception=err,
code=400,
)
Expand Down
4 changes: 2 additions & 2 deletions mfr/extensions/ipynb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class InvalidFormatError(RendererError):

__TYPE = 'ipynb_invalid_format'

def __init__(self, message, *args, code: int=400, download_url: str='',
original_exception: Exception=None, **kwargs):
def __init__(self, message, *args, code: int = 400, download_url: str = '',
original_exception: Exception = None, **kwargs):
super().__init__(message, *args, code=code, renderer_class='ipynb', **kwargs)

self.download_url = download_url,
Expand Down
1 change: 1 addition & 0 deletions mfr/extensions/ipynb/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def render(self):
'enabled': False,
},
}))

(body, _) = exporter.from_notebook_node(notebook)
return self.TEMPLATE.render(base=self.assets_url, body=body)

Expand Down
8 changes: 4 additions & 4 deletions mfr/extensions/jamovi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class JamoviVersionError(JamoviRendererError):

__TYPE = 'jamovi_version'

def __init__(self, message, *args, code: int=400, created_by: str='',
actual_version: str='', required_version: str='', **kwargs):
def __init__(self, message, *args, code: int = 400, created_by: str = '',
actual_version: str = '', required_version: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.created_by = created_by
self.actual_version = actual_version
Expand All @@ -34,8 +34,8 @@ class JamoviFileCorruptError(JamoviRendererError):

__TYPE = 'jamovi_file_corrupt'

def __init__(self, message, *args, code: int=400, corruption_type: str='',
reason: str='', **kwargs):
def __init__(self, message, *args, code: int = 400, corruption_type: str = '',
reason: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.corruption_type = corruption_type
self.reason = reason
Expand Down
8 changes: 4 additions & 4 deletions mfr/extensions/jasp/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class JaspVersionError(JaspRendererError):

__TYPE = 'jasp_version'

def __init__(self, message, *args, code: int=400, created_by: str='',
actual_version: str='', required_version: str='', **kwargs):
def __init__(self, message, *args, code: int = 400, created_by: str = '',
actual_version: str = '', required_version: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.created_by = created_by
self.actual_version = actual_version
Expand All @@ -34,8 +34,8 @@ class JaspFileCorruptError(JaspRendererError):

__TYPE = 'jasp_file_corrupt'

def __init__(self, message, *args, code: int=400, corruption_type: str='',
reason: str='', **kwargs):
def __init__(self, message, *args, code: int = 400, corruption_type: str = '',
reason: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.corruption_type = corruption_type
self.reason = reason
Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/jsc3d/freecad_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

try:
Part.open(in_fn)
except:
except Exception:
# Todo: maybe it is needed to use logger and specific message for exception logging
sys.exit(1)

Expand Down
7 changes: 3 additions & 4 deletions mfr/extensions/md/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@


class EscapeHtml(Extension):
def extendMarkdown(self, md, md_globals):
# Todo: do not see extendMarkdown explicit call and what is passed as the method args, maybe it is ok
del md.preprocessors['html_block']
del md.inlinePatterns['html']
def extendMarkdown(self, md):
md.preprocessors.deregister('html_block')
md.inlinePatterns.deregister('html')


class MdRenderer(extension.BaseRenderer):
Expand Down
4 changes: 2 additions & 2 deletions mfr/extensions/pdf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class PillowImageError(ExporterError):

__TYPE = 'pdf_pillow'

def __init__(self, message, *args, export_format: str='', detected_format: str='',
original_exception: Exception=None, **kwargs):
def __init__(self, message, *args, export_format: str = '', detected_format: str = '',
original_exception: Exception = None, **kwargs):
super().__init__(message, *args, exporter_class='image', **kwargs)

self.export_format = export_format
Expand Down
5 changes: 2 additions & 3 deletions mfr/extensions/pdf/export.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import logging
from http import HTTPStatus

Expand Down Expand Up @@ -93,7 +92,7 @@ def export(self):
'Unable to export the file as a {}, please check that the '
'file is a valid tiff image.'.format(export_type),
export_format=export_type,
detected_format= self.detect_image_format(),
detected_format=self.detect_image_format(),
original_exception=err,
code=HTTPStatus.BAD_REQUEST,
)
Expand All @@ -102,5 +101,5 @@ def detect_image_format(self):
try:
with Image.open(self.source_file_path) as img:
return img.format.lower()
except Exception as e:
except Exception:
return None
10 changes: 5 additions & 5 deletions mfr/extensions/tabular/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MissingRequirementsError(TabularRendererError):

__TYPE = 'tabular_missing_requirements'

def __init__(self, message, *args, code: int=500, function_preference: str='', **kwargs):
def __init__(self, message, *args, code: int = 500, function_preference: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.function_preference = function_preference
self.attr_stack.append([self.__TYPE, {'function_preference': self.function_preference}])
Expand All @@ -20,7 +20,7 @@ class EmptyTableError(TabularRendererError):

__TYPE = 'tabular_empty_table'

def __init__(self, message, *args, code: int=400, **kwargs):
def __init__(self, message, *args, code: int = 400, **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.attr_stack.append([self.__TYPE, {}])

Expand All @@ -29,7 +29,7 @@ class TableTooBigError(TabularRendererError):

__TYPE = 'tabular_table_too_big'

def __init__(self, message, *args, code: int=400, nbr_cols: int=0, nbr_rows: int=0, **kwargs):
def __init__(self, message, *args, code: int = 400, nbr_cols: int = 0, nbr_rows: int = 0, **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.nbr_cols = nbr_cols
self.nbr_rows = nbr_rows
Expand All @@ -43,7 +43,7 @@ class UnexpectedFormattingError(TabularRendererError):

__TYPE = 'tabular_unexpected_formatting'

def __init__(self, message, *args, code: int=500, formatting_function: str='', **kwargs):
def __init__(self, message, *args, code: int = 500, formatting_function: str = '', **kwargs):
super().__init__(message, *args, code=code, **kwargs)
self.formatting_function = formatting_function
self.attr_stack.append([self.__TYPE, {'formatting_function': self.formatting_function}])
Expand All @@ -53,7 +53,7 @@ class FileTooLargeError(TabularRendererError):

__TYPE = 'tabular_file_too_large'

def __init__(self, message, *args, code: int=400, file_size: int=None, max_size: int=None,
def __init__(self, message, *args, code: int = 400, file_size: int = None, max_size: int = None,
**kwargs):
super().__init__(message, *args, code=code, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/tabular/libs/panda_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def data_from_dataframe(dataframe):
data_row = {}
for name, value in frame_row.items():
try:
data_row[name] = numpy.asscalar(value)
data_row[name] = value.item()
except AttributeError:
data_row[name] = value
data.append(data_row)
Expand Down
Loading