mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Make tests clean up after themselves better. This means:
* call tearDown when Setup is called * shutil.rmtree the root of the created directory instead of just the leaf directory * set the LANGUAGE environment variable to what it was originally and not assume 'en'.
This commit is contained in:
		
							parent
							
								
									caf1c9dfe7
								
							
						
					
					
						commit
						4aebbb0449
					
				
					 1 changed files with 18 additions and 2 deletions
				
			
		| 
						 | 
					@ -46,6 +46,10 @@
 | 
				
			||||||
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
 | 
					LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
 | 
				
			||||||
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
 | 
					MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
 | 
				
			||||||
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
 | 
					UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
 | 
				
			||||||
 | 
					try:
 | 
				
			||||||
 | 
					    LANG = os.environ['LANGUAGE']
 | 
				
			||||||
 | 
					except:
 | 
				
			||||||
 | 
					    LANG = 'en'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GettextBaseTest(unittest.TestCase):
 | 
					class GettextBaseTest(unittest.TestCase):
 | 
				
			||||||
| 
						 | 
					@ -60,8 +64,8 @@ def setUp(self):
 | 
				
			||||||
        os.environ['LANGUAGE'] = 'xx'
 | 
					        os.environ['LANGUAGE'] = 'xx'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def tearDown(self):
 | 
					    def tearDown(self):
 | 
				
			||||||
        os.environ['LANGUAGE'] = 'en'
 | 
					        os.environ['LANGUAGE'] = LANG
 | 
				
			||||||
        shutil.rmtree(LOCALEDIR)
 | 
					        shutil.rmtree(os.path.split(LOCALEDIR)[0])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GettextTestCase1(GettextBaseTest):
 | 
					class GettextTestCase1(GettextBaseTest):
 | 
				
			||||||
| 
						 | 
					@ -71,6 +75,9 @@ def setUp(self):
 | 
				
			||||||
        self.mofile = MOFILE
 | 
					        self.mofile = MOFILE
 | 
				
			||||||
        gettext.install('gettext', self.localedir)
 | 
					        gettext.install('gettext', self.localedir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        GettextBaseTest.tearDown(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_some_translations(self):
 | 
					    def test_some_translations(self):
 | 
				
			||||||
        eq = self.assertEqual
 | 
					        eq = self.assertEqual
 | 
				
			||||||
        # test some translations
 | 
					        # test some translations
 | 
				
			||||||
| 
						 | 
					@ -137,6 +144,9 @@ def setUp(self):
 | 
				
			||||||
        # For convenience
 | 
					        # For convenience
 | 
				
			||||||
        self._ = gettext.gettext
 | 
					        self._ = gettext.gettext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        GettextBaseTest.tearDown(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_bindtextdomain(self):
 | 
					    def test_bindtextdomain(self):
 | 
				
			||||||
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
 | 
					        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -191,6 +201,9 @@ def setUp(self):
 | 
				
			||||||
        GettextBaseTest.setUp(self)
 | 
					        GettextBaseTest.setUp(self)
 | 
				
			||||||
        self.mofile = MOFILE
 | 
					        self.mofile = MOFILE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        GettextBaseTest.tearDown(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_plural_forms1(self):
 | 
					    def test_plural_forms1(self):
 | 
				
			||||||
        eq = self.assertEqual
 | 
					        eq = self.assertEqual
 | 
				
			||||||
        x = gettext.ngettext('There is %s file', 'There are %s files', 1)
 | 
					        x = gettext.ngettext('There is %s file', 'There are %s files', 1)
 | 
				
			||||||
| 
						 | 
					@ -279,6 +292,9 @@ def setUp(self):
 | 
				
			||||||
            fp.close()
 | 
					            fp.close()
 | 
				
			||||||
        self._ = self.t.ugettext
 | 
					        self._ = self.t.ugettext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
 | 
					        GettextBaseTest.tearDown(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_unicode_msgid(self):
 | 
					    def test_unicode_msgid(self):
 | 
				
			||||||
        unless = self.failUnless
 | 
					        unless = self.failUnless
 | 
				
			||||||
        unless(isinstance(self._(''), unicode))
 | 
					        unless(isinstance(self._(''), unicode))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue