Skip to content
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

fix: use custom context manager to use link between paths #40

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
21 changes: 16 additions & 5 deletions tests/test_cloudformation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import unittest
from contextlib import contextmanager
from pathlib import Path

import yaml
Expand All @@ -8,6 +9,15 @@
from cloudformation import CloudformationTemplate


@contextmanager
def link(link, target):
symlink = Path(link)
try:
yield symlink.symlink_to(target)
finally:
symlink.unlink()


class TestCloudFormation(unittest.TestCase):
def test_multi_constructor(self):
loader = cf.CFLoader(io.StringIO(""))
Expand Down Expand Up @@ -85,6 +95,8 @@ def setUp(self):
},
}

self.template_1 = "tests/fixtures/templates/example1.yml"

def test_load(self):
templates = (f"tests/fixtures/templates/example{i}.yml" for i in range(1, 3))

Expand All @@ -94,10 +106,9 @@ def test_load(self):
self.assertIsInstance(cloudformation.template, dict)
else:
with self.subTest(template=None):
symlink = Path("template.yml")
symlink.symlink_to("tests/fixtures/templates/example1.yml")
cloudformation = CloudformationTemplate()
symlink.unlink()
with link("template.yml", self.template_1):
cloudformation = CloudformationTemplate()

self.assertIsInstance(cloudformation.template, dict)

def test_load_raises_exception(self):
Expand All @@ -108,7 +119,7 @@ def test_load_raises_exception(self):
CloudformationTemplate(template)

def test_list_functions(self):
cloudformation = CloudformationTemplate("tests/fixtures/templates/example1.yml")
cloudformation = CloudformationTemplate(self.template_1)

expected_functions = [self.function]

Expand Down