Skip to content

Commit

Permalink
Add config inheritance test
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 18, 2024
1 parent 181afbd commit f8d3044
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,10 @@ def main(self):

# Merge all known command line flags into our global config object.

global global_config # pylint: disable=global-statement
global_config.start_filename = (
start_filename # pylint: disable=attribute-defined-outside-init
)
# pylint: disable=global-statement
global global_config
# pylint: disable=attribute-defined-outside-init
global_config.start_filename = start_filename
global_config |= flags.__dict__

# Unrecognized command line parameters also become global config fields if
Expand Down
8 changes: 8 additions & 0 deletions tests/config_child.hancho
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from hancho import *
import sys

# We should inherit config.foobar from our parent module.
if config.foobar != "config.foobar":
sys.exit(-1)

config.foobar = "this should not change config_parent.config.foobar"
10 changes: 10 additions & 0 deletions tests/config_parent.hancho
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from hancho import *
import sys

config.foobar = "config.foobar"

mod2 = load("config_child.hancho")

# Our child module should not be able to accidentally modify our config
if config.foobar != "config.foobar":
sys.exit(-1)
8 changes: 8 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def test_check_output(self):
"""A build rule that doesn't update one of its outputs should fail"""
self.assertNotEqual(0, run_hancho("check_output"))

def test_config_inheritance(self):
"""A module should inherit a config object extended from its parent, but should not be able
to modify its parent's config object."""
self.assertEqual(0, run_hancho("config_parent"))

# This should fail because it was expecting inheritance from its parent.
self.assertNotEqual(0, run_hancho("config_child"))

def test_recursive_base_is_bad(self):
"""Referring to base.attrib in a template is a bad idea"""
self.assertNotEqual(0, run_hancho("recursive_base_is_bad"))
Expand Down

0 comments on commit f8d3044

Please sign in to comment.