OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
gab
2013/07/26 20:39:48
2013
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import argparse | |
6 import json | |
7 import subprocess | |
8 import verifier | |
9 | |
10 class Config: | |
11 def __init__(self): | |
12 self.states = {} | |
13 self.actions = {} | |
14 self.tests = [] | |
15 | |
16 # Merge the new Property object into the current Property object | |
17 def MergeProperties(current_property, new_property): | |
18 for key, value in new_property.iteritems(): | |
19 if key not in current_property: | |
20 current_property[key] = value | |
21 else: | |
22 assert(isinstance(current_property[key], dict) and \ | |
robertshield
2013/07/26 19:32:23
\ not needed here
| |
23 isinstance(value, dict)) | |
24 current_property[key] = \ | |
25 dict(current_property[key].items() + value.items()) | |
robertshield
2013/07/26 19:32:23
hanging indents (that continue a statement) are us
gab
2013/07/26 20:39:48
This is the overriding merge I like but Robert doe
| |
26 | |
27 # Parse a .prop file | |
28 def ParseProperty(property_filename): | |
29 property_file = open(property_filename, "r") | |
30 property = json.load(property_file) | |
31 property_file.close() | |
32 return property | |
33 | |
robertshield
2013/07/26 19:32:23
I believe it is two blank lines between top-level
gab
2013/07/26 20:39:48
We should get someone with python readability to t
| |
34 # Parse an array of .prop files | |
35 def ParseProperties(property_filenames): | |
36 current_property = {} | |
37 for property_filename in property_filenames: | |
38 new_property = ParseProperty(property_filename) | |
39 MergeProperties(current_property, new_property) | |
40 return current_property | |
41 | |
42 # Parse a .config file | |
43 def ParseConfig(config_filename): | |
44 config = Config() | |
45 | |
46 config_file = open(config_filename, "r") | |
47 config_data = json.load(config_file) | |
48 config_file.close() | |
49 | |
50 for state_name, state_property_filenames in config_data["states"]: | |
51 config.states[state_name] = ParseProperties(state_property_filenames) | |
52 for action_name, action_command in config_data["actions"]: | |
53 config.actions[action_name] = action_command | |
54 config.tests = config_data["tests"] | |
55 return config | |
56 | |
57 # Verify that the current machine states match the given machine states | |
58 def VerifyState(config, state): | |
59 print " * Current state: " + state | |
gab
2013/07/26 20:39:48
What's the idea behind spaces + *? I guess it make
| |
60 verifier.Verify(config.states[state]) | |
61 | |
62 def RunCommand(command): | |
63 print " * Run command: " + command + "\n" | |
64 subprocess.call(command, shell=True) | |
65 | |
66 def RunResetCommand(): | |
67 print " * Reset\n" | |
68 subprocess.call("mini_installer.exe --chrome --uninstall" | |
gab
2013/07/26 20:39:48
I don't actually think that works... I don't think
| |
69 + " & mini_installer.exe --chrome-frame --uninstall", shell=True) # FIXME | |
robertshield
2013/07/26 19:32:23
indent 2 more
| |
70 | |
71 # Test the installer | |
72 def Test(config): | |
73 for test in config.tests: | |
74 print "Testing [ " + " -> ".join(test) + " ]" | |
gab
2013/07/26 20:39:48
What does this print exactly? The format appears w
sukolsak
2013/07/30 15:40:32
It joins the strings in the array with " -> ". So,
| |
75 | |
76 RunResetCommand() | |
77 | |
78 current_state = test[0] | |
79 VerifyState(config, current_state) | |
80 | |
81 for i in range(1, len(test), 2): | |
gab
2013/07/26 20:39:48
Perhaps assert that len(tests) is odd before runni
| |
82 action = test[i] | |
83 RunCommand(config.actions[action]) | |
84 | |
85 current_state = test[i + 1] | |
86 VerifyState(config, current_state) | |
87 | |
88 def main(): | |
89 parser = argparse.ArgumentParser(description="Test the installer.") | |
90 parser.add_argument("config_filename", help="the config file") | |
91 args = parser.parse_args() | |
92 | |
93 config = ParseConfig(args.config_filename) | |
94 Test(config) | |
95 | |
96 if __name__ == "__main__": | |
97 main() | |
OLD | NEW |