lib/bb/utils.py: Fix a bug in edit_metadata() that could corrupt vars
PATCH 1/2 lib/bb/utils.py: Fix a bug in edit_metadata() that could corrupt vars
edit_metadata() would corrupt a variable that was multiline, but had the ending quotes on the same line as the last value. For example:
TEST_VAR = " foo \
bar"would become " foo ba" because the code would always delete the last character on the line and then do it again if the line ended in the quote. This however doesn't show up if you have:
TEST_VAR = " foo \
bar \
"which is how all the test cases were written.
This patch fixes that bug and adds a fixes a test that matched the bugs behavior rather than the expected behavior.
--- lib/bb/tests/utils.py | 2 +- lib/bb/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
lib/bb/tests/utils.py +1 -1
@@ -176,7 +176,7 @@ do_functionname() { # Test file doesn't get modified with some the same values self._testeditfile({'THIS': ('that', None, 0, True), 'OTHER': ('anothervalue', None, 0, True), - 'MULTILINE3': (' c1 c2 c3', None, 4, False)}, self._origfile) + 'MULTILINE3': (' c1 c2 c3 ', None, 4, False)}, self._origfile) def test_edit_metadata_file_1(self):
lib/bb/utils.py +1 -1
@@ -1158,7 +1158,7 @@ def edit_metadata(meta_lines, variables, varfunc, match_overrides=False): if in_var.endswith('()'): if full_value.count('{') - full_value.count('}') >= 0: continue - full_value = full_value[:-1] + full_value = full_value[:-1] if handle_var_end(): updated = True checkspc = True
Signature · 1 line
2.5.5
PATCH 2/2 tests/utils.py: test origvalue in a callback matches what is expected
There were any tests that checked to make verify the value of origvalue in the callback routines used by edit_metadata(). This patch adds one for a simple multiline variable.
--- lib/bb/tests/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
lib/bb/tests/utils.py +22 -0
@@ -23,6 +23,7 @@ import unittest import bb import os import tempfile +import re class VerCmpString(unittest.TestCase):
@@ -377,6 +378,27 @@ do_functionname() { self.assertTrue(updated, 'List should be updated but isn\'t') self.assertEqual(newlines, newfile5.splitlines(True)) + # Make sure the orig value matches what we expect it to be + def test_edit_metadata_origvalue(self): + origfile = """ +MULTILINE = " stuff \\ + morestuff" +""" + expected_value = "stuff morestuff" + global value_in_callback + value_in_callback = "" + + def handle_var(varname, origvalue, op, newlines): + global value_in_callback + value_in_callback = origvalue + return (origvalue, op, -1, False) + + bb.utils.edit_metadata(origfile.splitlines(True), + ['MULTILINE'], + handle_var) + + testvalue = re.sub('\s+', ' ', value_in_callback.strip()) + self.assertEqual(expected_value, testvalue) class EditBbLayersConf(unittest.TestCase):
Signature · 1 line
2.5.5