FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 09-05-2011, 02:17 PM
Martin Gracik
 
Default isolate localeInfo and expandLangs() from langauges.py into a separate module.

looks fine to me

--

Martin Gracik

----- Original Message -----
> After 0c662ebeaf4043ff2e2a1f7d09b527f4bf243047, we can not build due
> to
> imports problem during build time (importing pyanaconda.constants
> tries to
> import pyanaconda.__init__ which tries to import isys etc.). This
> change
> separates the language.py bits and the bits needed during build time.
>
> Includes new unit tests.
> ---
> pyanaconda/gui.py | 1 -
> pyanaconda/iw/progress_gui.py | 4 +-
> pyanaconda/language.py | 54 ++------------------
> pyanaconda/localeinfo.py | 81 ++++++++++++++++++++++++++++++
> pyanaconda/text.py | 2 +-
> scripts/getlangnames.py | 12 ++--
> tests/pyanaconda_test/language_test.py | 12 ++--
> tests/pyanaconda_test/localeinfo_test.py | 35 +++++++++++++
> 8 files changed, 135 insertions(+), 66 deletions(-)
> create mode 100644 pyanaconda/localeinfo.py
> create mode 100644 tests/pyanaconda_test/localeinfo_test.py
>
> diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py
> index e306852..bd17653 100755
> --- a/pyanaconda/gui.py
> +++ b/pyanaconda/gui.py
> @@ -35,7 +35,6 @@ import shutil
> import gtk
> import gtk.glade
> import gobject
> -from language import expandLangs
> from constants import *
> from product import *
> import network
> diff --git a/pyanaconda/iw/progress_gui.py
> b/pyanaconda/iw/progress_gui.py
> index 2967092..93d4970 100644
> --- a/pyanaconda/iw/progress_gui.py
> +++ b/pyanaconda/iw/progress_gui.py
> @@ -28,7 +28,7 @@ from pyanaconda import gui
> from pyanaconda.flags import flags
> from iw_gui import *
> from pyanaconda.constants import *
> -from pyanaconda import language
> +from pyanaconda import localeinfo
>
> import logging
> log = logging.getLogger("anaconda")
> @@ -87,7 +87,7 @@ class InstallProgressWindow (InstallWindow):
> langs = []
> pixmaps = []
> if (os.environ.has_key('LANG')):
> - langs = language.expandLangs(os.environ['LANG'])
> + langs = localeinfo.expandLangs(os.environ['LANG'])
> langs.append(')
>
> pixmaps = []
> diff --git a/pyanaconda/language.py b/pyanaconda/language.py
> index b5dd94f..8a0d7f6 100644
> --- a/pyanaconda/language.py
> +++ b/pyanaconda/language.py
> @@ -27,6 +27,7 @@ import locale
>
> import gettext
> from pyanaconda.constants import ROOT_PATH
> +import localeinfo
> from simpleconfig import SimpleConfigFile
> import system_config_keyboard.keyboard as keyboard
>
> @@ -38,32 +39,6 @@ def langComponents(astring):
> m = pattern.match(astring)
> return m.groupdict()
>
> -# Converts a single language into a "language search path". For
> example,
> -# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
> -def expandLangs(astring):
> - langs = [astring]
> - charset = None
> - base = None
> -
> - # remove charset ...
> - if '.' in astring:
> - langs.append(string.split(astring, '.')[0])
> -
> - if '@' in astring:
> - charset = string.split(astring, '@')[1]
> -
> - if '_' in astring:
> - base = string.split(astring, '_')[0]
> -
> - if charset:
> - langs.append("%s@%s" % (base, charset))
> -
> - langs.append(base)
> - else:
> - langs.append(astring[:2])
> -
> - return langs
> -
> class Language(object):
> def _setInstLang(self, value):
> # Always store in its full form so we know what we're comparing with.
> @@ -147,7 +122,6 @@ class Language(object):
> self._default = "en_US.UTF-8"
> self.displayMode = display_mode
> self.info = {}
> - self.localeInfo = {}
> self.nativeLangNames = {}
>
> # English name -> native name mapping
> @@ -163,27 +137,7 @@ class Language(object):
> f.close()
> break
>
> - # nick -> (name, short name, font, keyboard, timezone) mapping
> - search = ('lang-table', '/tmp/updates/lang-table',
> '/etc/lang-table',
> - '/usr/share/anaconda/lang-table')
> - for path in search:
> - if os.access(path, os.R_OK):
> - f = open(path, "r")
> - for line in f.readlines():
> - string.strip(line)
> - l = string.split(line, ' ')
> -
> - # throw out invalid lines
> - if len(l) < 6:
> - continue
> -
> - self.localeInfo[l[3]] = (l[0], l[1], l[2], l[4], string.strip(l[5]))
> -
> - f.close()
> - break
> -
> - # Hard code this to prevent errors in the build environment.
> - self.localeInfo['C'] = self.localeInfo[self._default]
> + self.localeInfo = localeinfo.get(self._default)
>
> # instLang must be set after localeInfo is populated, in case the
> # current setting is unsupported by anaconda..
> @@ -199,7 +153,7 @@ class Language(object):
> fr_CA -> ValueError
> """
> for key in self.localeInfo.keys():
> - if lang in expandLangs(key):
> + if lang in localeinfo.expandLangs(key):
> return key
>
> raise ValueError
> @@ -229,7 +183,7 @@ class Language(object):
> return args
>
> def getCurrentLangSearchList(self):
> - return expandLangs(self.systemLang) + ['C']
> + return localeinfo.expandLangs(self.systemLang) + ['C']
>
> def getDefaultKeyboard(self):
> try:
> diff --git a/pyanaconda/localeinfo.py b/pyanaconda/localeinfo.py
> new file mode 100644
> index 0000000..f036358
> --- /dev/null
> +++ b/pyanaconda/localeinfo.py
> @@ -0,0 +1,81 @@
> +# __init__.py
> +# Entry point for anaconda's storage configuration module.
> +#
> +# Copyright (C) 2009 Red Hat, Inc.
> +#
> +# This copyrighted material is made available to anyone wishing to
> use,
> +# modify, copy, or redistribute it subject to the terms and
> conditions of
> +# the GNU General Public License v.2, or (at your option) any later
> version.
> +# This program is distributed in the hope that it will be useful, but
> WITHOUT
> +# ANY WARRANTY expressed or implied, including the implied warranties
> of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> General
> +# Public License for more details. You should have received a copy of
> the
> +# GNU General Public License along with this program; if not, write
> to the
> +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
> Boston, MA
> +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in
> the
> +# source code or documentation are not subject to the GNU General
> Public
> +# License and may only be used or replicated with the express
> permission of
> +# Red Hat, Inc.
> +#
> +
> +
> +""" Basic locale operations useful during both Anaconda build time
> and run time.
> +
> + This module can be imported without importing pyanaconda/__init__.py
> and it
> + is desirable to keep it that way.
> +"""
> +
> +import os
> +import string
> +
> +def get(default):
> + localeInfo = {}
> + # nick -> (name, short name, font, keyboard, timezone) mapping
> + search = ('lang-table', '/tmp/updates/lang-table',
> '/etc/lang-table',
> + '/usr/share/anaconda/lang-table')
> + for path in search:
> + if os.access(path, os.R_OK):
> + f = open(path, "r")
> + for line in f.readlines():
> + string.strip(line)
> + l = string.split(line, ' ')
> +
> + # throw out invalid lines
> + if len(l) < 6:
> + continue
> +
> + localeInfo[l[3]] = (l[0], l[1], l[2], l[4], string.strip(l[5]))
> +
> + f.close()
> + break
> +
> + # Hard code this to prevent errors in the build environment.
> + localeInfo['C'] = localeInfo[default]
> + return localeInfo
> +
> +# Converts a single language into a "language search path". For
> example,
> +# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
> +def expandLangs(astring):
> + langs = [astring]
> + charset = None
> + base = None
> +
> + # remove charset ...
> + if '.' in astring:
> + langs.append(string.split(astring, '.')[0])
> +
> + if '@' in astring:
> + charset = string.split(astring, '@')[1]
> +
> + if '_' in astring:
> + base = string.split(astring, '_')[0]
> +
> + if charset:
> + langs.append("%s@%s" % (base, charset))
> +
> + langs.append(base)
> + else:
> + langs.append(astring[:2])
> +
> + return langs
> +
> diff --git a/pyanaconda/text.py b/pyanaconda/text.py
> index 6396f25..cb85bb5 100644
> --- a/pyanaconda/text.py
> +++ b/pyanaconda/text.py
> @@ -32,7 +32,7 @@ import signal
> import parted
> import product
> import string
> -from language import expandLangs
> +from localeinfo import expandLangs
> from flags import flags
> from textw.constants_text import *
> from constants import *
> diff --git a/scripts/getlangnames.py b/scripts/getlangnames.py
> index bc3cced..2e579a4 100644
> --- a/scripts/getlangnames.py
> +++ b/scripts/getlangnames.py
> @@ -19,26 +19,26 @@
>
> import sys
> sys.path.append("..")
> -import language as language
> +import localeinfo
>
> import gettext
>
> -langs = language.Language()
> +localeInfo = localeinfo.get("en_US.UTF-8")
> names = {}
> -for k in langs.localeInfo.keys():
> +for k in localeInfo.keys():
> found = False
> - for l in language.expandLangs(k):
> + for l in localeinfo.expandLangs(k):
> try:
> f = open("../po/%s.gmo" %(l,))
> except (OSError, IOError):
> continue
> cat = gettext.GNUTranslations(f)
> cat.set_output_charset("utf-8")
> - names[langs.localeInfo[k][0]] = cat.lgettext(langs.localeInfo[k][0])
> + names[localeInfo[k][0]] = cat.lgettext(localeInfo[k][0])
> found = True
> break
> if not found:
> - names[langs.localeInfo[k][0]] = langs.localeInfo[k][0]
> + names[localeInfo[k][0]] = localeInfo[k][0]
>
> nameList = names.keys()
> nameList.sort()
> diff --git a/tests/pyanaconda_test/language_test.py
> b/tests/pyanaconda_test/language_test.py
> index 3d4498a..daf500b 100644
> --- a/tests/pyanaconda_test/language_test.py
> +++ b/tests/pyanaconda_test/language_test.py
> @@ -13,12 +13,7 @@ class LanguageTest(mock.TestCase):
> self.fs = mock.DiskIO()
>
> def fake_os_access(path, _):
> - return path == 'lang-table' or path == 'lang-names'
> -
> - self.fs.open('lang-table', 'w').write(
> - "Czech cs latarcyrheb-sun16 cs_CZ.UTF-8 cz-lat2 Europe/Prague
"
> - "English en latarcyrheb-sun16 en_US.UTF-8 us America/New_York
"
> - "Hebrew he none he_IL.UTF-8 us Asia/Jerusalem")
> + return path == 'lang-names'
>
> self.fs.open('lang-names', 'w').write(
> "Czech Cestina
"
> @@ -33,6 +28,11 @@ class LanguageTest(mock.TestCase):
> pyanaconda.language.os.access = fake_os_access
> pyanaconda.language.os.environ = {'LANG': ENVIRON_LANG}
> pyanaconda.language.locale = mock.Mock()
> + pyanaconda.language.localeinfo.get = mock.Mock(return_value={
> + 'C': ('English', 'en', 'latarcyrheb-sun16', 'us',
> 'America/New_York'),
> + 'cs_CZ.UTF-8': ('Czech', 'cs', 'latarcyrheb-sun16', 'cz-lat2',
> 'Europe/Prague'),
> + 'en_US.UTF-8': ('English', 'en', 'latarcyrheb-sun16', 'us',
> 'America/New_York'),
> + 'he_IL.UTF-8': ('Hebrew', 'he', 'none', 'us', 'Asia/Jerusalem')})
>
> def tearDown(self):
> self.tearDownModules()
> diff --git a/tests/pyanaconda_test/localeinfo_test.py
> b/tests/pyanaconda_test/localeinfo_test.py
> new file mode 100644
> index 0000000..32f0916
> --- /dev/null
> +++ b/tests/pyanaconda_test/localeinfo_test.py
> @@ -0,0 +1,35 @@
> +import mock
> +
> +class LocaleinfoTest(mock.TestCase):
> + def setUp(self):
> + self.setupModules(
> + ['_isys', 'logging', 'pyanaconda.anaconda_log', 'block'])
> +
> + import pyanaconda
> + pyanaconda.anaconda_log = mock.Mock()
> +
> + def tearDown(self):
> + self.tearDownModules()
> +
> + def expandLangs_test(self):
> + from pyanaconda import localeinfo
> + exp = localeinfo.expandLangs("fr_FR.utf8@euro")
> + self.assertEqual(exp, ['fr_FR.utf8@euro', 'fr_FR', 'fr@euro', 'fr'])
> +
> + def get_test(self):
> + from pyanaconda import localeinfo
> +
> + fs = mock.DiskIO()
> + fs['/lang-table'] = """
> +Czech cs latarcyrheb-sun16 cs_CZ.UTF-8 cz-lat2 Europe/Prague

> +English en latarcyrheb-sun16 en_US.UTF-8 us America/New_York

> +Hebrew he none he_IL.UTF-8 us Asia/Jerusalem"""
> + self.take_over_io(fs, localeinfo)
> +
> + info = localeinfo.get("en_US.UTF-8")
> + self.assertEqual(
> + info,
> + {'C': ('English', 'en', 'latarcyrheb-sun16', 'us',
> 'America/New_York'),
> + 'cs_CZ.UTF-8': ('Czech', 'cs', 'latarcyrheb-sun16', 'cz-lat2',
> 'Europe/Prague'),
> + 'en_US.UTF-8': ('English', 'en', 'latarcyrheb-sun16', 'us',
> 'America/New_York'),
> + 'he_IL.UTF-8': ('Hebrew', 'he', 'none', 'us', 'Asia/Jerusalem')})
> --
> 1.7.6
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 09-06-2011, 05:19 PM
David Cantrell
 
Default isolate localeInfo and expandLangs() from langauges.py into a separate module.

Comments below.

On 09/05/2011 09:51 AM, Ales Kozumplik wrote:

After 0c662ebeaf4043ff2e2a1f7d09b527f4bf243047, we can not build due to
imports problem during build time (importing pyanaconda.constants tries to
import pyanaconda.__init__ which tries to import isys etc.). This change
separates the language.py bits and the bits needed during build time.

Includes new unit tests.
---
pyanaconda/gui.py | 1 -
pyanaconda/iw/progress_gui.py | 4 +-
pyanaconda/language.py | 54 ++------------------
pyanaconda/localeinfo.py | 81 ++++++++++++++++++++++++++++++
pyanaconda/text.py | 2 +-
scripts/getlangnames.py | 12 ++--
tests/pyanaconda_test/language_test.py | 12 ++--
tests/pyanaconda_test/localeinfo_test.py | 35 +++++++++++++
8 files changed, 135 insertions(+), 66 deletions(-)
create mode 100644 pyanaconda/localeinfo.py
create mode 100644 tests/pyanaconda_test/localeinfo_test.py

diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py
index e306852..bd17653 100755
--- a/pyanaconda/gui.py
+++ b/pyanaconda/gui.py
@@ -35,7 +35,6 @@ import shutil
import gtk
import gtk.glade
import gobject
-from language import expandLangs
from constants import *
from product import *
import network
diff --git a/pyanaconda/iw/progress_gui.py b/pyanaconda/iw/progress_gui.py
index 2967092..93d4970 100644
--- a/pyanaconda/iw/progress_gui.py
+++ b/pyanaconda/iw/progress_gui.py
@@ -28,7 +28,7 @@ from pyanaconda import gui
from pyanaconda.flags import flags
from iw_gui import *
from pyanaconda.constants import *
-from pyanaconda import language
+from pyanaconda import localeinfo

import logging
log = logging.getLogger("anaconda")
@@ -87,7 +87,7 @@ class InstallProgressWindow (InstallWindow):
langs = []
pixmaps = []
if (os.environ.has_key('LANG')):
- langs = language.expandLangs(os.environ['LANG'])
+ langs = localeinfo.expandLangs(os.environ['LANG'])
langs.append(')

pixmaps = []
diff --git a/pyanaconda/language.py b/pyanaconda/language.py
index b5dd94f..8a0d7f6 100644
--- a/pyanaconda/language.py
+++ b/pyanaconda/language.py
@@ -27,6 +27,7 @@ import locale

import gettext
from pyanaconda.constants import ROOT_PATH
+import localeinfo
from simpleconfig import SimpleConfigFile
import system_config_keyboard.keyboard as keyboard

@@ -38,32 +39,6 @@ def langComponents(astring):
m = pattern.match(astring)
return m.groupdict()

-# Converts a single language into a "language search path". For example,
-# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
-def expandLangs(astring):
- langs = [astring]
- charset = None
- base = None
-
- # remove charset ...
- if '.' in astring:
- langs.append(string.split(astring, '.')[0])
-
- if '@' in astring:
- charset = string.split(astring, '@')[1]
-
- if '_' in astring:
- base = string.split(astring, '_')[0]
-
- if charset:
- langs.append("%s@%s" % (base, charset))
-
- langs.append(base)
- else:
- langs.append(astring[:2])
-
- return langs
-
class Language(object):
def _setInstLang(self, value):
# Always store in its full form so we know what we're comparing with.
@@ -147,7 +122,6 @@ class Language(object):
self._default = "en_US.UTF-8"
self.displayMode = display_mode
self.info = {}
- self.localeInfo = {}
self.nativeLangNames = {}

# English name -> native name mapping
@@ -163,27 +137,7 @@ class Language(object):
f.close()
break

- # nick -> (name, short name, font, keyboard, timezone) mapping
- search = ('lang-table', '/tmp/updates/lang-table', '/etc/lang-table',
- '/usr/share/anaconda/lang-table')
- for path in search:
- if os.access(path, os.R_OK):
- f = open(path, "r")
- for line in f.readlines():
- string.strip(line)
- l = string.split(line, ' ')
-
- # throw out invalid lines
- if len(l)< 6:
- continue
-
- self.localeInfo[l[3]] = (l[0], l[1], l[2], l[4], string.strip(l[5]))
-
- f.close()
- break
-
- # Hard code this to prevent errors in the build environment.
- self.localeInfo['C'] = self.localeInfo[self._default]
+ self.localeInfo = localeinfo.get(self._default)

# instLang must be set after localeInfo is populated, in case the
# current setting is unsupported by anaconda..
@@ -199,7 +153,7 @@ class Language(object):
fr_CA -> ValueError
"""
for key in self.localeInfo.keys():
- if lang in expandLangs(key):
+ if lang in localeinfo.expandLangs(key):
return key

raise ValueError
@@ -229,7 +183,7 @@ class Language(object):
return args

def getCurrentLangSearchList(self):
- return expandLangs(self.systemLang) + ['C']
+ return localeinfo.expandLangs(self.systemLang) + ['C']

def getDefaultKeyboard(self):
try:
diff --git a/pyanaconda/localeinfo.py b/pyanaconda/localeinfo.py
new file mode 100644
index 0000000..f036358
--- /dev/null
+++ b/pyanaconda/localeinfo.py
@@ -0,0 +1,81 @@
+# __init__.py
+# Entry point for anaconda's storage configuration module.


No it's not.


+#
+# Copyright (C) 2009 Red Hat, Inc.


2011


+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+
+
+""" Basic locale operations useful during both Anaconda build time and run time.
+
+ This module can be imported without importing pyanaconda/__init__.py and it
+ is desirable to keep it that way.
+"""
+
+import os
+import string
+
+def get(default):
+ localeInfo = {}
+ # nick -> (name, short name, font, keyboard, timezone) mapping
+ search = ('lang-table', '/tmp/updates/lang-table', '/etc/lang-table',
+ '/usr/share/anaconda/lang-table')
+ for path in search:
+ if os.access(path, os.R_OK):
+ f = open(path, "r")
+ for line in f.readlines():
+ string.strip(line)
+ l = string.split(line, ' ')
+
+ # throw out invalid lines
+ if len(l)< 6:
+ continue
+
+ localeInfo[l[3]] = (l[0], l[1], l[2], l[4], string.strip(l[5]))
+
+ f.close()
+ break
+
+ # Hard code this to prevent errors in the build environment.
+ localeInfo['C'] = localeInfo[default]
+ return localeInfo
+
+# Converts a single language into a "language search path". For example,
+# fr_FR.utf8@euro would become "fr_FR.utf8@euro fr_FR.utf8 fr_FR fr"
+def expandLangs(astring):
+ langs = [astring]
+ charset = None
+ base = None
+
+ # remove charset ...
+ if '.' in astring:
+ langs.append(string.split(astring, '.')[0])
+
+ if '@' in astring:
+ charset = string.split(astring, '@')[1]
+
+ if '_' in astring:
+ base = string.split(astring, '_')[0]
+
+ if charset:
+ langs.append("%s@%s" % (base, charset))
+
+ langs.append(base)
+ else:
+ langs.append(astring[:2])
+
+ return langs
+
diff --git a/pyanaconda/text.py b/pyanaconda/text.py
index 6396f25..cb85bb5 100644
--- a/pyanaconda/text.py
+++ b/pyanaconda/text.py
@@ -32,7 +32,7 @@ import signal
import parted
import product
import string
-from language import expandLangs
+from localeinfo import expandLangs
from flags import flags
from textw.constants_text import *
from constants import *
diff --git a/scripts/getlangnames.py b/scripts/getlangnames.py
index bc3cced..2e579a4 100644
--- a/scripts/getlangnames.py
+++ b/scripts/getlangnames.py
@@ -19,26 +19,26 @@

import sys
sys.path.append("..")
-import language as language
+import localeinfo

import gettext

-langs = language.Language()
+localeInfo = localeinfo.get("en_US.UTF-8")
names = {}
-for k in langs.localeInfo.keys():
+for k in localeInfo.keys():
found = False
- for l in language.expandLangs(k):
+ for l in localeinfo.expandLangs(k):
try:
f = open("../po/%s.gmo" %(l,))
except (OSError, IOError):
continue
cat = gettext.GNUTranslations(f)
cat.set_output_charset("utf-8")
- names[langs.localeInfo[k][0]] = cat.lgettext(langs.localeInfo[k][0])
+ names[localeInfo[k][0]] = cat.lgettext(localeInfo[k][0])
found = True
break
if not found:
- names[langs.localeInfo[k][0]] = langs.localeInfo[k][0]
+ names[localeInfo[k][0]] = localeInfo[k][0]

nameList = names.keys()
nameList.sort()
diff --git a/tests/pyanaconda_test/language_test.py b/tests/pyanaconda_test/language_test.py
index 3d4498a..daf500b 100644
--- a/tests/pyanaconda_test/language_test.py
+++ b/tests/pyanaconda_test/language_test.py
@@ -13,12 +13,7 @@ class LanguageTest(mock.TestCase):
self.fs = mock.DiskIO()

def fake_os_access(path, _):
- return path == 'lang-table' or path == 'lang-names'
-
- self.fs.open('lang-table', 'w').write(
- "Czech cs latarcyrheb-sun16 cs_CZ.UTF-8 cz-lat2 Europe/Prague
"
- "English en latarcyrheb-sun16 en_US.UTF-8 us America/New_York
"
- "Hebrew he none he_IL.UTF-8 us Asia/Jerusalem")
+ return path == 'lang-names'

self.fs.open('lang-names', 'w').write(
"Czech Cestina
"
@@ -33,6 +28,11 @@ class LanguageTest(mock.TestCase):
pyanaconda.language.os.access = fake_os_access
pyanaconda.language.os.environ = {'LANG': ENVIRON_LANG}
pyanaconda.language.locale = mock.Mock()
+ pyanaconda.language.localeinfo.get = mock.Mock(return_value={
+ 'C': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'),
+ 'cs_CZ.UTF-8': ('Czech', 'cs', 'latarcyrheb-sun16', 'cz-lat2', 'Europe/Prague'),
+ 'en_US.UTF-8': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'),
+ 'he_IL.UTF-8': ('Hebrew', 'he', 'none', 'us', 'Asia/Jerusalem')})

def tearDown(self):
self.tearDownModules()
diff --git a/tests/pyanaconda_test/localeinfo_test.py b/tests/pyanaconda_test/localeinfo_test.py
new file mode 100644
index 0000000..32f0916
--- /dev/null
+++ b/tests/pyanaconda_test/localeinfo_test.py
@@ -0,0 +1,35 @@
+import mock
+
+class LocaleinfoTest(mock.TestCase):
+ def setUp(self):
+ self.setupModules(
+ ['_isys', 'logging', 'pyanaconda.anaconda_log', 'block'])
+
+ import pyanaconda
+ pyanaconda.anaconda_log = mock.Mock()
+
+ def tearDown(self):
+ self.tearDownModules()
+
+ def expandLangs_test(self):
+ from pyanaconda import localeinfo
+ exp = localeinfo.expandLangs("fr_FR.utf8@euro")
+ self.assertEqual(exp, ['fr_FR.utf8@euro', 'fr_FR', 'fr@euro', 'fr'])
+
+ def get_test(self):
+ from pyanaconda import localeinfo
+
+ fs = mock.DiskIO()
+ fs['/lang-table'] = """
+Czech cs latarcyrheb-sun16 cs_CZ.UTF-8 cz-lat2 Europe/Prague

+English en latarcyrheb-sun16 en_US.UTF-8 us America/New_York

+Hebrew he none he_IL.UTF-8 us Asia/Jerusalem"""
+ self.take_over_io(fs, localeinfo)
+
+ info = localeinfo.get("en_US.UTF-8")
+ self.assertEqual(
+ info,
+ {'C': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'),
+ 'cs_CZ.UTF-8': ('Czech', 'cs', 'latarcyrheb-sun16', 'cz-lat2', 'Europe/Prague'),
+ 'en_US.UTF-8': ('English', 'en', 'latarcyrheb-sun16', 'us', 'America/New_York'),
+ 'he_IL.UTF-8': ('Hebrew', 'he', 'none', 'us', 'Asia/Jerusalem')})




--
David Cantrell <dcantrell@redhat.com>
Supervisor, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 06:04 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org