[damned-lies] Use assertIsInstance in vertimus tests



commit 6248d42ef2c60942574a5fa0f2524b49a40a289e
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat Mar 25 15:36:27 2017 +0100

    Use assertIsInstance in vertimus tests

 vertimus/tests/tests.py |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 598e7d6..3c10b19 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -248,7 +248,7 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('RT', person=self.pt)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Reserved!"})
-        self.assertTrue(isinstance(state, StateTranslating))
+        self.assertIsInstance(state, StateTranslating)
 
     @test_scratchdir
     def test_action_ut(self):
@@ -260,17 +260,17 @@ class VertimusTest(TeamsAndRolesTests):
         state = StateTranslating(branch=self.b, domain=self.d, language=self.l, person=self.pt)
         state.save()
 
-        test_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "valid_po.po"), 'r')
-
-        action = Action.new_by_name('UT', person=self.pt, file=File(test_file))
-        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Done by translator."})
+        file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "valid_po.po")
+        with open(file_path, 'r') as test_file:
+            action = Action.new_by_name('UT', person=self.pt, file=File(test_file))
+            action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Done by translator."})
 
         self.assertEqual(action.file.url, '/media/upload/gedit-gnome-2-24-po-fr-%d.po' % state.id)
         self.assertEqual(action.merged_file.url, '/media/upload/gedit-gnome-2-24-po-fr-%d.merged.po' % 
state.id)
         # Merged file will not be really produced as no pot file exists on the file system
         self.files_to_clean.append(action.file.path)
 
-        self.assertTrue(isinstance(state, StateTranslated))
+        self.assertIsInstance(state, StateTranslated)
         # Mail sent to mailing list
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].recipients(), [self.l.team.mailing_list])
@@ -288,7 +288,7 @@ class VertimusTest(TeamsAndRolesTests):
         action.apply_on(state, {
             'send_to_ml': action.send_mail_to_ml, 'comment': "",
         })
-        self.assertTrue(isinstance(state, StateProofreading))
+        self.assertIsInstance(state, StateProofreading)
         self.assertEqual(len(mail.outbox), 0)
 
     def test_action_rp_with_comment(self):
@@ -316,7 +316,7 @@ class VertimusTest(TeamsAndRolesTests):
         action = Action.new_by_name('UP', person=self.pr, file=test_file)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Done."})
         self.files_to_clean.append(action.file.path)
-        self.assertTrue(isinstance(state, StateProofread))
+        self.assertIsInstance(state, StateProofread)
         # Mail sent to mailing list
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].recipients(), [self.l.team.mailing_list])
@@ -339,7 +339,7 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('TC', person=self.pr)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Ready!"})
-        self.assertTrue(isinstance(state, StateToCommit))
+        self.assertIsInstance(state, StateToCommit)
 
     def test_action_rc(self):
         state = StateToCommit(branch=self.b, domain=self.d, language=self.l)
@@ -347,7 +347,7 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('RC', person=self.pc)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "This work is mine!"})
-        self.assertTrue(isinstance(state, StateCommitting))
+        self.assertIsInstance(state, StateCommitting)
 
     def test_action_ci(self):
         self.b.module.vcs_root = self.b.module.vcs_root.replace('git://', 'ssh://')
@@ -443,7 +443,7 @@ class VertimusTest(TeamsAndRolesTests):
         # Team is French (but translations may not be compiled/up-to-date)
         self.assertTrue('Commité' in mail.outbox[0].body or "Committed" in mail.outbox[0].body)
 
-        self.assertTrue(isinstance(state, StateNone))
+        self.assertIsInstance(state, StateNone)
         self.assertTrue(not os.access(file_path, os.F_OK), "%s not deleted" % file_path)
 
         # Remove test file
@@ -458,7 +458,7 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('TR', person=self.pc)
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml, 'comment': "Bad work :-/"})
-        self.assertTrue(isinstance(state, StateToReview))
+        self.assertIsInstance(state, StateToReview)
 
     def test_action_aa(self):
         state = StateCommitted(branch=self.b, domain=self.d, language=self.l, person=self.pr)
@@ -470,7 +470,7 @@ class VertimusTest(TeamsAndRolesTests):
         })
 
         state = State.objects.get(branch=self.b, domain=self.d, language=self.l)
-        self.assertTrue(isinstance(state, StateNone))
+        self.assertIsInstance(state, StateNone)
         self.assertEqual(state.action_set.count(), 0)
 
     def test_action_undo(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]