Skip to content

Commit

Permalink
created class Mockfile for load_yaml_file
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonySinitsa committed Aug 9, 2023
1 parent db02242 commit 7f55de7
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion tests/test_LangTrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import os
from re import error as re_error
from re import compile as re_compile
from LangTrans.LangTrans import sanitize_regex
from LangTrans.LangTrans import check_collections
from LangTrans.LangTrans import extract_token_options
Expand All @@ -12,7 +13,7 @@
from LangTrans.LangTrans import report_syntax_error
from LangTrans.LangTrans import match_parts
from LangTrans.LangTrans import find_outside_errors
from LangTrans.LangTrans import convert_syntax
from LangTrans.LangTrans import convert_syntax, _ParseYAMLDetails
from LangTrans.LangTrans import find_substring_lines
from LangTrans.LangTrans import load_yaml_file
from LangTrans.LangTrans import extract_yaml_details
Expand Down Expand Up @@ -132,11 +133,56 @@ def test_replace_variables_empty(global_variables):

# test find_outside_errors



# test convert_syntax
@pytest.fixture
def example_yaml_details():
match_rules = {
'part1': 'pattern1',
'part2': 'pattern2'
}
transform_rules = {
'part1': ({"token1": {"replace": [("pattern", "replacement")]}}, None),
'part2': ({"token2": {"eachline": "<line>"}}, None)
}
outside_errors = None
pattern_templates = {'part1': '<pattern1>', 'part2': '<pattern2>'}

return (
(match_rules, transform_rules, outside_errors),
pattern_templates
)


# test find_substring_lines



# test load_yaml_file
class MockFile:
def __init__(self, content):
self.content = content

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
pass

def read(self):
return self.content

def mock_open(file, *args, **kwargs):
if file.endswith(".yaml"):
return MockFile("data: example")
else:
raise FileNotFoundError

# Apply the mock_open function to the built-in open function
@pytest.fixture(autouse=True)
def mock_builtin_open(monkeypatch):
monkeypatch.setattr("builtins.open", mock_open)

# test extract_yaml_details

Expand Down

0 comments on commit 7f55de7

Please sign in to comment.