Skip to content

Commit

Permalink
Fixed linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pescheck-bram committed Aug 21, 2024
1 parent 75888d9 commit c32217b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions python_gpt_po/po_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@


import argparse
import json
import logging
import os
import json
from tenacity import retry, stop_after_attempt, wait_fixed

import polib
from dotenv import load_dotenv
from openai import OpenAI
from tenacity import retry, stop_after_attempt, wait_fixed

from python_gpt_po.version import __version__

Expand Down
21 changes: 10 additions & 11 deletions python_gpt_po/tests/test_po_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
This module contains unit tests for the PO Translator.
"""

import logging
from unittest.mock import MagicMock, patch

import polib
import pytest
import logging

from python_gpt_po.po_translator import TranslationConfig, TranslationService, POFileHandler
from python_gpt_po.po_translator import POFileHandler, TranslationConfig, TranslationService

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -87,14 +86,14 @@ def test_process_po_file(mock_po_file_handler_class, translation_service, tmp_pa
msgstr ""
'''
po_file_path.write_text(po_file_content)

# Mock POFileHandler methods
mock_po_file_handler = mock_po_file_handler_class.return_value
mock_po_file_handler.get_file_language.return_value = 'es'

# Explicitly setting fuzzy=True to trigger the function
translation_service.config.fuzzy = True

# Process the .po file
translation_service.process_po_file(str(po_file_path), ['es'])

Expand All @@ -105,12 +104,12 @@ def test_translate_bulk(translation_service, tmp_path):
"""
texts_to_translate = ["HR", "TENANT", "HEALTHCARE", "TRANSPORT", "SERVICES"]
po_file_path = str(tmp_path / "django.po")

# Mock the response to return a list of translations, as expected by the translation function
translation_service.config.client.chat.completions.create.return_value.choices[0].message.content = (
'["HR", "Inquilino", "Salud", "Transporte", "Servicios"]'
)

translated_texts = translation_service.translate_bulk(texts_to_translate, 'es', po_file_path)

# Since the response is a list, you should assert against the list items
Expand All @@ -122,10 +121,10 @@ def test_translate_single(translation_service):
Test the single translation functionality.
"""
text_to_translate = "HEALTHCARE"

# Mock the response to return a single translation string
translation_service.config.client.chat.completions.create.return_value.choices[0].message.content = 'Salud'

translated_text = translation_service.translate_single(text_to_translate, 'es')

assert translated_text == "Salud"
Expand All @@ -145,4 +144,4 @@ def test_validate_translation(translation_service):
long_translation = "This is a very long translation that should be rejected"
validated_long = translation_service.validate_translation(original, long_translation)

assert validated_long != long_translation
assert validated_long != long_translation

0 comments on commit c32217b

Please sign in to comment.