pungi/tests/test_ostree_utils.py
Haibo Lin 3eddcfccd8 Fix flake8 complaints - F401
F401 'dnf' imported but unused
F401 'imp' imported but unused
F401 'os' imported but unused
F401 'subprocess' imported but unused
F401 'sys' imported but unused
F401 'yum' imported but unused

JIRA: COMPOSE-4108
Signed-off-by: Haibo Lin <hlin@redhat.com>
2020-02-07 11:48:31 +08:00

50 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
import mock
import os
from tests import helpers
from pungi.ostree import utils
class GetRefFromTreefileTest(helpers.PungiTestCase):
def setUp(self):
super(GetRefFromTreefileTest, self).setUp()
self.json = os.path.join(self.topdir, "treefile.json")
self.yaml = os.path.join(self.topdir, "treefile.yaml")
def test_reads_json(self):
helpers.touch(self.json, """{"ref": "master"}""")
self.assertEqual(utils.get_ref_from_treefile(self.json), "master")
def test_reads_yaml(self):
helpers.touch(self.yaml, """ref: master""")
self.assertEqual(utils.get_ref_from_treefile(self.yaml), "master")
@mock.patch("pungi.ostree.utils.getBaseArch")
def test_replaces_basearch(self, getBaseArch):
getBaseArch.return_value = "x86_64"
helpers.touch(self.json, """{"ref": "${basearch}/master"}""")
self.assertEqual(utils.get_ref_from_treefile(self.json), "x86_64/master")
@mock.patch("pungi.ostree.utils.getBaseArch")
def test_replaces_basearch_for_given_arch(self, getBaseArch):
getBaseArch.return_value = "x86_64"
helpers.touch(self.json, """{"ref": "${basearch}/master"}""")
self.assertEqual(
utils.get_ref_from_treefile(self.json, arch="foo"), "x86_64/master"
)
self.assertEqual(getBaseArch.call_args_list, [mock.call("foo")])
def test_handles_invalid_json(self):
helpers.touch(self.json, """{"ref" "master"}""")
self.assertIsNone(utils.get_ref_from_treefile(self.json))
def test_handles_invalid_yaml(self):
helpers.touch(self.yaml, """{ ref\n - master""")
self.assertIsNone(utils.get_ref_from_treefile(self.yaml))
def test_handles_missing_file(self):
self.assertIsNone(utils.get_ref_from_treefile(self.json))