예제 #1
0
 def test_default_none(self):
     ays = AreYouSure()
     with captured_output() as (out, err):
         self.assertFalse(ays(input='NONE'))
     with captured_output() as (out, err):
         self.assertFalse(ays())
     self.assertEqual(out.getvalue(), '')
     ays.reset_all()
     with captured_output() as (out, err):
         self.assertTrue(ays(input='y'))
     self.assertEqual(out.getvalue(),
                      'Are you sure [yes,y,no(default),ALL,NONE] ? ')
예제 #2
0
 def test_message(self):
     ays = AreYouSure(message='R U OK')
     with captured_output() as (out, err):
         self.assertTrue(ays(input='y'))
     self.assertEqual(out.getvalue(),
                      'R U OK [yes,y,no(default),ALL,NONE] ? ')
     with captured_output() as (out, err):
         self.assertTrue(ays(message='Proceed', input='y'))
     self.assertEqual(out.getvalue(),
                      'Proceed [yes,y,no(default),ALL,NONE] ? ')
예제 #3
0
 def test_french(self):
     ays = AreYouSure(**AreYouSure.french_defaults)
     with captured_output() as (out, err):
         self.assertTrue(ays(input='oui'))
         self.assertEqual(
             out.getvalue(),
             'Etes-vous sûr [oui,o,non(défault),TOUS,AUCUN] ? ')
         self.assertTrue(ays(input='o'))
         self.assertTrue(ays(input='O'))
         self.assertFalse(ays(input=''))
         self.assertFalse(ays(input='non'))
         self.assertFalse(ays(input='whatever'))
예제 #4
0
 def test_default_single(self):
     ays = AreYouSure()
     with captured_output() as (out, err):
         self.assertTrue(ays(input='yes'))
         self.assertEqual(out.getvalue(),
                          'Are you sure [yes,y,no(default),ALL,NONE] ? ')
         self.assertEqual(err.getvalue(), '')
         self.assertTrue(ays(input='y'))
         self.assertTrue(ays(input='Y'))
         self.assertFalse(ays(input=''))
         self.assertFalse(ays(input='no'))
         self.assertFalse(ays(input='whatever'))
예제 #5
0
def copy(source, force=False, *dest):
    ays = AreYouSure(output='stderr')
    for d in dest:
        if os.path.exists(d) and (force
                                  or ays('%s already exists, replace it' % d)):
            print("replacing %s" % d)
예제 #6
0
 def test_stderr(self):
     ays = AreYouSure(output='stderr')
     with captured_output() as (out, err):
         self.assertTrue(ays(input='yes'))
     self.assertEqual(err.getvalue(),
                      'Are you sure [yes,y,no(default),ALL,NONE] ? ')
예제 #7
0
 def test_default_yes(self):
     ays = AreYouSure(yes_default='y')
     with captured_output() as (out, err):
         self.assertTrue(ays(input=''))
         self.assertEqual(out.getvalue(),
                          'Are you sure [yes,y(default),ALL,NONE] ? ')