Update control_data to be more verbose about which file it failed to parse
Added syntax error check that prints file and line when an error is found
Risk: Low
Visibility: Errors that just said 'Your control file don't have the proper variables'
now actually specifies which file is at fault
Signed-off-by: Scott Zawalski <scottz@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2223 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/control_data.py b/client/common_lib/control_data.py
index 5477d6b..952e6a0 100644
--- a/client/common_lib/control_data.py
+++ b/client/common_lib/control_data.py
@@ -2,7 +2,7 @@
#
# Copyright 2008 Google Inc. Released under the GPL v2
-import compiler, textwrap, types
+import compiler, textwrap, types, sys
REQUIRED_VARS = set(['author', 'doc', 'name', 'time', 'test_class',
@@ -13,8 +13,9 @@
class ControlData(object):
- def __init__(self, vars, raise_warnings=False):
+ def __init__(self, vars, path, raise_warnings=False):
# Defaults
+ self.path = path
self.dependencies = set()
self.experimental = False
self.run_verify = True
@@ -23,8 +24,8 @@
diff = REQUIRED_VARS - set(vars)
if len(diff) > 0:
warning = ("WARNING: Not all required control "
- "variables were specified. Please define "
- "%s.") % ', '.join(diff)
+ "variables were specified in %s. Please define "
+ "%s.") % (self.path, ', '.join(diff))
if raise_warnings:
raise ControlVariableException(warning)
print textwrap.wrap(warning, 80)
@@ -168,7 +169,11 @@
def parse_control(path, raise_warnings=False):
- mod = compiler.parseFile(path)
+ try:
+ mod = compiler.parseFile(path)
+ except SyntaxError, e:
+ print "Error parsing %s because %s" % (path, e)
+ sys.exit(1)
assert(mod.__class__ == compiler.ast.Module)
assert(mod.node.__class__ == compiler.ast.Stmt)
@@ -184,4 +189,4 @@
except AssertionError, e:
pass
- return ControlData(vars, raise_warnings)
+ return ControlData(vars, path, raise_warnings)
diff --git a/client/common_lib/control_data_unittest.py b/client/common_lib/control_data_unittest.py
index 194e172..51ea8a5 100644
--- a/client/common_lib/control_data_unittest.py
+++ b/client/common_lib/control_data_unittest.py
@@ -21,6 +21,7 @@
TEST_TYPE='client'
"""
+
class ParseControlTest(unittest.TestCase):
def setUp(self):
fp, self.control_file = tempfile.mkstemp(text=True)
@@ -58,7 +59,7 @@
def test_bool(self):
- cd = ControlData({})
+ cd = ControlData({}, 'filename')
cd._set_bool('foo', 'False')
self.assertEquals(cd.foo, False)
cd._set_bool('foo', True)
@@ -74,7 +75,7 @@
def test_int(self):
- cd = ControlData({})
+ cd = ControlData({}, 'filename')
cd._set_int('foo', 0)
self.assertEquals(cd.foo, 0)
cd._set_int('foo', '0')
@@ -89,7 +90,7 @@
def test_set(self):
- cd = ControlData({})
+ cd = ControlData({}, 'filename')
cd._set_set('foo', 'a')
self.assertEquals(cd.foo, set(['a']))
cd._set_set('foo', 'a,b,c')
@@ -101,7 +102,7 @@
def test_string(self):
- cd = ControlData({})
+ cd = ControlData({}, 'filename')
cd._set_string('foo', 'a')
self.assertEquals(cd.foo, 'a')
cd._set_string('foo', 'b')
@@ -118,7 +119,7 @@
def test_option(self):
options = ['a', 'b']
- cd = ControlData({})
+ cd = ControlData({}, 'filename')
cd._set_option('foo', 'a', options)
self.assertEquals(cd.foo, 'a')
cd._set_option('foo', 'b', options)