Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 8 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"name": "Struct devcontainer",
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.12"
},
"name": "Struct devcontainer",
"image": "mcr.microsoft.com/devcontainers/python:3",
"features": {
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/gvatsal60/dev-container-features/pre-commit": {},
"ghcr.io/eitsupi/devcontainer-features/go-task:latest": {},
"ghcr.io/devcontainers-extra/features/shfmt:1" : {}
},
"postCreateCommand": "bash ./scripts/devcontainer_start.sh",
"customizations": {
"ghcr.io/eitsupi/devcontainer-features/go-task:latest": {}
},
"postCreateCommand": "bash ./scripts/devcontainer_start.sh",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
Expand Down
6 changes: 3 additions & 3 deletions scripts/devcontainer_start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pip3.12 install -r requirements.txt
pip3.12 install -r requirements.dev.txt
pip3.12 install -e .
pip install -r requirements.txt
pip install -r requirements.dev.txt
pip install -e .
14 changes: 12 additions & 2 deletions struct_module/file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ def fetch_content(self):
if self.content_location:
self.logger.debug(f"Fetching content from: {self.content_location}")
try:
self.content = self.content_fetcher.fetch_content(self.content_location)
self.logger.debug(f"Fetched content: {self.content}")
raw_content = self.content_fetcher.fetch_content(
self.content_location)
self.logger.debug(f"Fetched content: {raw_content}")
# Render the fetched content using the template renderer
template_vars = self._merge_default_template_vars(
self.config_variables)
missing_vars = self.template_renderer.prompt_for_missing_vars(
raw_content, template_vars)
template_vars.update(missing_vars)
self.content = self.template_renderer.render_template(
raw_content, template_vars)
self.logger.debug(f"Rendered content: {self.content}")
except Exception as e:
self.logger.error(f"❗ Failed to fetch content from {self.content_location}: {e}")

Expand Down
34 changes: 34 additions & 0 deletions tests/test_file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,37 @@ def test_fetch_content(file_item):
mock_fetch.return_value = "fetched content"
file_item.fetch_content()
assert file_item.content == "file content"


def test_fetch_content_renders_template(monkeypatch):
properties = {
"name": "test.txt",
"file": "/fake/path.txt",
"config_variables": [],
"input_store": "/tmp/input.json"
}
file_item = FileItem(properties)

# Mock fetch_content to return a template string
monkeypatch.setattr(
file_item.content_fetcher,
"fetch_content",
lambda location: "Hello, {{@ name @}}!"
)
# Mock template renderer methods
rendered = {}

def fake_prompt_for_missing_vars(content, vars):
return {"name": "World"}

def fake_render_template(content, vars):
rendered["content"] = content
rendered["vars"] = vars
return "Hello, World!"
file_item.template_renderer.prompt_for_missing_vars = fake_prompt_for_missing_vars
file_item.template_renderer.render_template = fake_render_template

file_item.fetch_content()
assert file_item.content == "Hello, World!"
assert rendered["content"] == "Hello, {{@ name @}}!"
assert rendered["vars"]["name"] == "World"
Loading