From c6585448589d690d019776d0754688a738919edc Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Thu, 28 Sep 2023 14:26:56 -0400 Subject: [PATCH] Add tests for dockerfile paths to ensure backwards compatibility Signed-off-by: Ethan Paul --- tests/test_parser.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_parser.py b/tests/test_parser.py index a66cf50..2fd8915 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -14,6 +14,7 @@ import pytest import re import sys +from pathlib import Path from textwrap import dedent from dockerfile_parse import DockerfileParser @@ -1521,3 +1522,18 @@ def test_alt_dockerfile_names(self, tmpdir): validate = DockerfileParser(path=tmpdir, dockerfile_filename="Containerfile") assert validate.baseimage == out.baseimage + + def test_dockerfile_path_compatibility(self, tmpdir): + tmpdir = Path(tmpdir) + parser = DockerfileParser(path=tmpdir) + assert str(parser.dockerfile) == parser.dockerfile_path + assert parser.dockerfile == tmpdir / "Dockerfile" + + with (tmpdir / "nothing").open("w+") as testfile: + nullparser = DockerfileParser(fileobj=testfile) + assert nullparser.dockerfile is None + assert nullparser.dockerfile_path is None + + newfile = tmpdir / "nowhere" + parser.dockerfile_path = str(newfile) + assert parser.dockerfile == newfile