| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import os | |
| 5 import tempfile | 4 import tempfile |
| 6 import unittest | 5 import unittest |
| 7 | 6 |
| 8 from telemetry import page_set | 7 from telemetry import page_set |
| 9 | 8 |
| 10 simple_archive_info = """ | |
| 11 { | |
| 12 "archives": { | |
| 13 "data_01.wpr": ["http://www.foo.com/"], | |
| 14 "data_02.wpr": ["http://www.bar.com/"] | |
| 15 } | |
| 16 } | |
| 17 """ | |
| 18 | |
| 19 simple_set = """ | 9 simple_set = """ |
| 20 {"description": "hello", | 10 {"description": "hello", |
| 21 "archive_data_file": "%s", | 11 "archive_path": "foo.wpr", |
| 22 "pages": [ | 12 "pages": [ |
| 23 {"url": "http://www.foo.com/"}, | 13 {"url": "http://www.foo.com/"} |
| 24 {"url": "http://www.bar.com/"} | |
| 25 ] | 14 ] |
| 26 } | 15 } |
| 27 """ | 16 """ |
| 28 | 17 |
| 29 class TestPageSet(unittest.TestCase): | 18 class TestPageSet(unittest.TestCase): |
| 30 def testSimpleSet(self): | 19 def testSimpleSet(self): |
| 31 with tempfile.NamedTemporaryFile() as f: | 20 with tempfile.NamedTemporaryFile() as f: |
| 32 f.write(simple_archive_info) | 21 f.write(simple_set) |
| 33 f.flush() | 22 f.flush() |
| 34 archive_data_file = f.name | 23 ps = page_set.PageSet.FromFile(f.name) |
| 35 | |
| 36 with tempfile.NamedTemporaryFile() as f2: | |
| 37 f2.write(simple_set % archive_data_file) | |
| 38 f2.flush() | |
| 39 ps = page_set.PageSet.FromFile(f2.name) | |
| 40 | 24 |
| 41 self.assertEquals('hello', ps.description) | 25 self.assertEquals('hello', ps.description) |
| 42 self.assertEquals(archive_data_file, ps.archive_data_file) | 26 self.assertEquals('foo.wpr', ps.archive_path) |
| 43 self.assertEquals(2, len(ps.pages)) | 27 self.assertEquals(1, len(ps.pages)) |
| 44 self.assertEquals('http://www.foo.com/', ps.pages[0].url) | 28 self.assertEquals('http://www.foo.com/', ps.pages[0].url) |
| 45 self.assertEquals('http://www.bar.com/', ps.pages[1].url) | |
| 46 self.assertEquals('data_01.wpr', os.path.basename(ps.pages[0].archive_path)) | |
| 47 self.assertEquals('data_02.wpr', os.path.basename(ps.pages[1].archive_path)) | |
| OLD | NEW |