Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1547)

Side by Side Diff: testing/tools/common.py

Issue 1057983003: Refactor PDFium python test utilities. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Tidy. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | testing/tools/pngdiffer.py » ('j') | testing/tools/run_corpus_tests.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2015 The PDFium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import sys
8
9 def os_name():
10 if sys.platform.startswith('linux'):
11 return 'linux'
12 if sys.platform.startswith('win'):
13 return 'win'
14 if sys.platform.startswith('darwin'):
15 return 'mac'
16 raise Exception('Confused, can not determine OS, aborting.')
17
18
19 class DirectoryFinder:
20 '''A class for finding directories and paths under either a standalone
21 checkout or a chromium checkout of PDFium.'''
22
23 def __init__(self, build_type):
Lei Zhang 2015/04/03 19:50:27 You may want to add a comment to explain what buil
Tom Sepez 2015/04/03 20:19:50 Done.
24 # Expect |my_dir| to be .../pdfium/testing/tools.
25 self.my_dir = os.path.dirname(os.path.realpath(__file__))
26 self.testing_dir = os.path.dirname(self.my_dir)
27 if (os.path.basename(self.my_dir) != 'tools' or
28 os.path.basename(self.testing_dir) != 'testing'):
29 raise Exception('Confused, can not find pdfium root directory, aborting.')
30 self.pdfium_dir = os.path.dirname(self.testing_dir)
31 # Find path to build directory. This depends on whether this is a
32 # standalone build vs. a build as part of a chromium checkout. For
33 # standalone, we expect a path like .../pdfium/out/Debug, but for
34 # chromium, we expect a path like .../src/out/Debug two levels
35 # higher (to skip over the third_party/pdfium path component under
36 # which chromium sticks pdfium).
37 self.base_dir = self.pdfium_dir
38 one_up_dir = os.path.dirname(self.base_dir)
39 two_up_dir = os.path.dirname(one_up_dir)
40 if (os.path.basename(two_up_dir) == 'src' and
41 os.path.basename(one_up_dir) == 'third_party'):
42 self.base_dir = two_up_dir
43 self.build_dir = os.path.join(self.base_dir, build_type)
44 self.os_name = os_name()
45
46 def ExecutablePath(self, name):
47 '''Finds compiled binaries under the build path.'''
48 result = os.path.join(self.build_dir, name)
49 if self.os_name == 'win':
50 result = result + '.exe'
51 return result
52
53 def ScriptPath(self, name):
54 '''Finds other scripts in the same directory as this one.'''
55 return os.path.join(self.my_dir, name)
56
57 def WorkingDir(self, other_components=''):
58 '''Places generated files under the build directory, not source dir.'''
59 result = os.path.join(self.build_dir, 'gen', 'pdfium')
60 if other_components:
61 result = os.path.join(result, other_components)
62 return result
63
64 def TestingDir(self, other_components=''):
65 '''Finds test files somewhere under the testing directory.'''
66 result = self.testing_dir
67 if other_components:
68 result = os.path.join(result, other_components)
69 return result
OLDNEW
« no previous file with comments | « no previous file | testing/tools/pngdiffer.py » ('j') | testing/tools/run_corpus_tests.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698