Skip to content

Commit

Permalink
Change grit to depend on test data in the main repository.
Browse files Browse the repository at this point in the history
BUG=82636
TEST=python tools/grit/grit.py unit

Review URL: http://codereview.chromium.org/7269003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91161 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
joi@chromium.org committed Jun 30, 2011
1 parent 764062b commit b32bd6e
Show file tree
Hide file tree
Showing 66 changed files with 6,449 additions and 55 deletions.
8 changes: 4 additions & 4 deletions tools/grit/grit/clique_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -98,8 +98,8 @@ def testAllInUberClique(self):
</message>
</messages>
<structures>
<structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="grit/test/data/klonk.rc" />
<structure type="tr_html" name="ID_HTML" file="grit/test/data/simple.html" />
<structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="grit/testdata/klonk.rc" />
<structure type="tr_html" name="ID_HTML" file="grit/testdata/simple.html" />
</structures>
</release>
</grit>''')), util.PathFromRoot('.'))
Expand All @@ -119,7 +119,7 @@ def testCorrectExceptionIfWrongEncodingOnResourceFile(self):
<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="3">
<structures>
<structure type="dialog" name="IDD_ABOUTBOX" file="grit/test/data/klonk.rc" />
<structure type="dialog" name="IDD_ABOUTBOX" file="grit/testdata/klonk.rc" />
</structures>
</release>
</grit>''')), util.PathFromRoot('.'))
Expand Down
12 changes: 6 additions & 6 deletions tools/grit/grit/format/rc_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def testMessages(self):
def testRcSection(self):
root = grd_reader.Parse(StringIO.StringIO('''
<structures>
<structure type="menu" name="IDC_KLONKMENU" file="grit\\test\data\klonk.rc" encoding="utf-16" />
<structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
<structure type="version" name="VS_VERSION_INFO" file="grit\\test\data\klonk.rc" encoding="utf-16" />
<structure type="menu" name="IDC_KLONKMENU" file="grit\\testdata\klonk.rc" encoding="utf-16" />
<structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
<structure type="version" name="VS_VERSION_INFO" file="grit\\testdata\klonk.rc" encoding="utf-16" />
</structures>'''), flexible_root = True)
util.FixRootForUnittest(root)
root.RunGatherers(recursive = True)
Expand Down Expand Up @@ -184,7 +184,7 @@ def testRcIncludeFile(self):
self.failUnless(output.strip() == expected)

def testRcIncludeFlattenedHtmlFile(self):
input_file = util.PathFromRoot('grit/test/data/include_test.html')
input_file = util.PathFromRoot('grit/testdata/include_test.html')
output_file = '%s/HTML_FILE1_include_test.html' % tempfile.gettempdir()
root = grd_reader.Parse(StringIO.StringIO('''
<includes>
Expand Down Expand Up @@ -223,7 +223,7 @@ def testRcIncludeFlattenedHtmlFile(self):


def testStructureNodeOutputfile(self):
input_file = util.PathFromRoot('grit/test/data/simple.html')
input_file = util.PathFromRoot('grit/testdata/simple.html')
root = grd_reader.Parse(StringIO.StringIO(
'<structure type="tr_html" name="IDR_HTML" file="%s" />' %input_file),
flexible_root = True)
Expand Down Expand Up @@ -251,7 +251,7 @@ def testFallbackToEnglish(self):
<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<release seq="1" allow_pseudo="False">
<structures fallback_to_english="True">
<structure type="dialog" name="IDD_ABOUTBOX" file="grit\\test\data\klonk.rc" encoding="utf-16" />
<structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" />
</structures>
</release>
</grit>'''), util.PathFromRoot('.'))
Expand Down
19 changes: 9 additions & 10 deletions tools/grit/grit/gather/admin_template_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -49,11 +49,11 @@ def testErrorHandling(self):
gatherer.Parse)

_TRANSLATABLES_FROM_FILE = (
'Google', 'Google Desktop Search', 'Preferences',
'Controls Google Deskop Search preferences',
'Google', 'Google Desktop', 'Preferences',
'Controls Google Desktop preferences',
'Indexing and Capture Control',
'Controls what files, web pages, and other content will be indexed by Google Desktop Search.',
'Prevent indexing of e-mail',
'Controls what files, web pages, and other content will be indexed by Google Desktop.',
'Prevent indexing of email',
# there are lots more but we don't check any further
)

Expand All @@ -64,7 +64,7 @@ def VerifyCliquesFromAdmFile(self, cliques):
self.failUnless(text == self._TRANSLATABLES_FROM_FILE[ix])

def testFromFile(self):
fname = util.PathFromRoot('grit/test/data/GoogleDesktopSearch.adm')
fname = util.PathFromRoot('grit/testdata/GoogleDesktop.adm')
gatherer = admin_template.AdmGatherer.FromFile(fname)
gatherer.Parse()
cliques = gatherer.GetCliques()
Expand All @@ -76,15 +76,15 @@ def MakeGrd(self):
<release seq="3">
<structures>
<structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH"
file="GoogleDesktopSearch.adm" exclude_from_rc="true" />
file="GoogleDesktop.adm" exclude_from_rc="true" />
<structure type="txt" name="BINGOBONGO"
file="README.txt" exclude_from_rc="true" />
</structures>
</release>
<outputs>
<output filename="de_res.rc" type="rc_all" lang="de" />
</outputs>
</grit>'''), util.PathFromRoot('grit/test/data'))
</grit>'''), util.PathFromRoot('grit/testdata'))
grd.RunGatherers(recursive=True)
return grd

Expand All @@ -104,7 +104,7 @@ def testFileIsOutput(self):
tool.Process()

self.failUnless(os.path.isfile(
os.path.join(dirname, 'de_GoogleDesktopSearch.adm')))
os.path.join(dirname, 'de_GoogleDesktop.adm')))
self.failUnless(os.path.isfile(
os.path.join(dirname, 'de_README.txt')))
finally:
Expand All @@ -114,4 +114,3 @@ def testFileIsOutput(self):

if __name__ == '__main__':
unittest.main()

12 changes: 7 additions & 5 deletions tools/grit/grit/gather/rc_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -20,7 +20,7 @@

class RcUnittest(unittest.TestCase):

part_we_want = '''IDC_KLONKACC ACCELERATORS
part_we_want = '''IDC_KLONKACC ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
Expand All @@ -45,10 +45,13 @@ def testSectionFromFile(self):
out = rc.Section.FromFile(f, 'IDC_KLONKACC')
self.failUnless(out.GetText() == self.part_we_want)

out = rc.Section.FromFile(util.PathFromRoot(r'grit/test/data/klonk.rc'),
out = rc.Section.FromFile(util.PathFromRoot(r'grit/testdata/klonk.rc'),
'IDC_KLONKACC',
encoding='utf-16')
self.failUnless(out.GetText() == self.part_we_want)
out_text = out.GetText().replace('\t', '')
out_text = out_text.replace(' ', '')
self.part_we_want = self.part_we_want.replace(' ', '')
self.failUnless(out_text.strip() == self.part_we_want.strip())


def testDialog(self):
Expand Down Expand Up @@ -363,4 +366,3 @@ def Check():

if __name__ == '__main__':
unittest.main()

15 changes: 7 additions & 8 deletions tools/grit/grit/gather/tr_html_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -241,7 +241,7 @@ def testExplicitDescriptions(self):

def testRegressionInToolbarAbout(self):
html = tr_html.TrHtml.FromFile(
util.PathFromRoot(r'grit/test/data/toolbar_about.html'))
util.PathFromRoot(r'grit/testdata/toolbar_about.html'))
html.Parse()
cliques = html.GetCliques()
for cl in cliques:
Expand All @@ -267,7 +267,7 @@ def HtmlFromFileWithManualCheck(self, f):

def testPrivacyHtml(self):
html = self.HtmlFromFileWithManualCheck(
util.PathFromRoot(r'grit/test/data/privacy.html'))
util.PathFromRoot(r'grit/testdata/privacy.html'))

self.failUnless(html.skeleton_[1].GetMessage().GetRealContent() ==
'Privacy and Google Desktop Search')
Expand All @@ -277,7 +277,7 @@ def testPrivacyHtml(self):

def testPreferencesHtml(self):
html = self.HtmlFromFileWithManualCheck(
util.PathFromRoot(r'grit/test/data/preferences.html'))
util.PathFromRoot(r'grit/testdata/preferences.html'))

# Verify that we don't get '[STATUS-MESSAGE]' as the original content of
# one of the MessageClique objects (it would be a placeholder-only message
Expand All @@ -300,7 +300,7 @@ def AssertNumberOfTranslateables(self, files, num):
num: 3
'''
for f in files:
f = util.PathFromRoot(r'grit/test/data/%s' % f)
f = util.PathFromRoot(r'grit/testdata/%s' % f)
html = self.HtmlFromFileWithManualCheck(f)
self.failUnless(len(html.GetCliques()) == num)

Expand All @@ -325,7 +325,7 @@ def testOtherHtmlFilesForManualInspection(self):
]
for f in files:
self.HtmlFromFileWithManualCheck(
util.PathFromRoot(r'grit/test/data/%s' % f))
util.PathFromRoot(r'grit/testdata/%s' % f))

def testTranslate(self):
# Note that the English translation of documents that use character
Expand Down Expand Up @@ -399,7 +399,7 @@ def testRegressionCjkHtmlFile(self):
# match never to return. (culprit is the _ELEMENT regexp(
if False:
html = self.HtmlFromFileWithManualCheck(util.PathFromRoot(
r'grit/test/data/ko_oem_enable_bug.html'))
r'grit/testdata/ko_oem_enable_bug.html'))
self.failUnless(True)

def testRegressionCpuHang(self):
Expand All @@ -410,4 +410,3 @@ def testRegressionCpuHang(self):

if __name__ == '__main__':
unittest.main()

4 changes: 2 additions & 2 deletions tools/grit/grit/grd_reader_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -145,7 +145,7 @@ def testAssignFirstIdsMultipleMessages(self):
'..')
root.AssignFirstIds(
os.path.join(grit_root_dir, "../../test.grd"),
os.path.join(grit_root_dir, "grit/test/data/resource_ids"),
os.path.join(grit_root_dir, "grit/testdata/resource_ids"),
{})
messages_node = root.children[0].children[0]
self.assertTrue(isinstance(messages_node, empty.MessagesNode))
Expand Down
4 changes: 2 additions & 2 deletions tools/grit/grit/grit_runner_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -27,7 +27,7 @@ def tearDown(self):

def testSimple(self):
grit.grit_runner.Main(['-i',
util.PathFromRoot('grit/test/data/simple-input.xml'),
util.PathFromRoot('grit/testdata/simple-input.xml'),
'-d', 'test', 'bla', 'voff', 'ga'])
output = self.buf.getvalue()
self.failUnless(output.count('disconnected'))
Expand Down
10 changes: 5 additions & 5 deletions tools/grit/grit/node/io_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -45,15 +45,15 @@ def testLoadTranslations(self):
grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<translations>
<file path="fr.xtb" lang="fr" />
<file path="generated_resources_fr.xtb" lang="fr" />
</translations>
<release seq="3">
<messages>
<message name="ID_HELLO">Hello!</message>
<message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message>
</messages>
</release>
</grit>'''), util.PathFromRoot('grit/test/data'))
</grit>'''), util.PathFromRoot('grit/testdata'))
grd.RunGatherers(recursive=True)
self.failUnless(True)

Expand All @@ -62,7 +62,7 @@ def testIffyness(self):
<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
<translations>
<if expr="lang == 'fr'">
<file path="fr.xtb" lang="fr" />
<file path="generated_resources_fr.xtb" lang="fr" />
</if>
</translations>
<release seq="3">
Expand All @@ -71,7 +71,7 @@ def testIffyness(self):
<message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message>
</messages>
</release>
</grit>'''), util.PathFromRoot('grit/test/data'))
</grit>'''), util.PathFromRoot('grit/testdata'))
grd.SetOutputContext('en', {})
grd.RunGatherers(recursive=True)

Expand Down
11 changes: 5 additions & 6 deletions tools/grit/grit/node/misc_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand All @@ -24,14 +24,14 @@ class GritNodeUnittest(unittest.TestCase):
def testUniqueNameAttribute(self):
try:
restree = grd_reader.Parse(
util.PathFromRoot('grit/test/data/duplicate-name-input.xml'))
util.PathFromRoot('grit/testdata/duplicate-name-input.xml'))
self.fail('Expected parsing exception because of duplicate names.')
except grit.exception.Parsing:
pass # Expected case

def testReadFirstIdsFromFile(self):
test_resource_ids = os.path.join(os.path.dirname(__file__), '..', 'test',
'data', 'resource_ids')
test_resource_ids = os.path.join(os.path.dirname(__file__), '..',
'testdata', 'resource_ids')
id_dict = misc._ReadFirstIdsFromFile(
test_resource_ids,
{
Expand Down Expand Up @@ -175,7 +175,7 @@ def testPseudoControl(self):
<structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" />
</structures>
</release>
</grit>'''), util.PathFromRoot('grit/test/data'))
</grit>'''), util.PathFromRoot('grit/testdata'))
grd.RunGatherers(recursive=True)

hello = grd.GetNodeById('IDS_HELLO')
Expand Down Expand Up @@ -207,4 +207,3 @@ def testPseudoControl(self):

if __name__ == '__main__':
unittest.main()

Loading

0 comments on commit b32bd6e

Please sign in to comment.