161
161
class TestExecution(script.TestCaseWithTransportAndScript):
163
163
def test_unknown_command(self):
164
"""A clear error is reported for commands that aren't recognised
166
Testing the attributes of the SyntaxError instance is equivalent to
167
using traceback.format_exception_only and comparing with:
168
File "<string>", line 1
171
SyntaxError: Command not found "foo"
173
e = self.assertRaises(SyntaxError, self.run_script, "$ foo --frob")
174
self.assertContainsRe(e.msg, "not found.*foo")
175
self.assertEquals(e.text, "foo --frob")
164
self.assertRaises(SyntaxError, self.run_script, 'foo')
177
166
def test_blank_output_mismatches_output(self):
178
167
"""If you give output, the output must actually be blank.
189
def test_null_output_matches_option(self):
190
"""If you want null output to be a wild card, you can pass
191
null_output_matches_anything to run_script"""
195
""", null_output_matches_anything=True)
197
178
def test_ellipsis_everything(self):
198
179
"""A simple ellipsis matches everything."""
199
180
self.run_script("""
386
self.assertPathExists('dir')
387
self.assertPathExists('dir2')
367
self.failUnlessExists('dir')
368
self.failUnlessExists('dir2')
390
371
class TestCd(script.TestCaseWithTransportAndScript):
481
462
def test_rm_file(self):
482
463
self.run_script('$ echo content >file')
483
self.assertPathExists('file')
464
self.failUnlessExists('file')
484
465
self.run_script('$ rm file')
485
self.assertPathDoesNotExist('file')
466
self.failIfExists('file')
487
468
def test_rm_file_force(self):
488
self.assertPathDoesNotExist('file')
469
self.failIfExists('file')
489
470
self.run_script('$ rm -f file')
490
self.assertPathDoesNotExist('file')
471
self.failIfExists('file')
492
473
def test_rm_files(self):
493
474
self.run_script("""
494
475
$ echo content >file
495
476
$ echo content >file2
497
self.assertPathExists('file2')
478
self.failUnlessExists('file2')
498
479
self.run_script('$ rm file file2')
499
self.assertPathDoesNotExist('file2')
480
self.failIfExists('file2')
501
482
def test_rm_dir(self):
502
483
self.run_script('$ mkdir dir')
503
self.assertPathExists('dir')
484
self.failUnlessExists('dir')
504
485
self.run_script("""
506
487
2>rm: cannot remove 'dir': Is a directory
508
self.assertPathExists('dir')
489
self.failUnlessExists('dir')
510
491
def test_rm_dir_recursive(self):
511
492
self.run_script("""
515
self.assertPathDoesNotExist('dir')
496
self.failIfExists('dir')
518
499
class TestMv(script.TestCaseWithTransportAndScript):
525
506
def test_move_file(self):
526
507
self.run_script('$ echo content >file')
527
self.assertPathExists('file')
508
self.failUnlessExists('file')
528
509
self.run_script('$ mv file new_name')
529
self.assertPathDoesNotExist('file')
530
self.assertPathExists('new_name')
510
self.failIfExists('file')
511
self.failUnlessExists('new_name')
532
513
def test_move_unknown_file(self):
533
514
self.assertRaises(AssertionError,
539
520
$ echo content >dir/file
541
522
self.run_script('$ mv dir new_name')
542
self.assertPathDoesNotExist('dir')
543
self.assertPathExists('new_name')
544
self.assertPathExists('new_name/file')
523
self.failIfExists('dir')
524
self.failUnlessExists('new_name')
525
self.failUnlessExists('new_name/file')
546
527
def test_move_file_into_dir(self):
547
528
self.run_script("""
549
530
$ echo content > file
551
532
self.run_script('$ mv file dir')
552
self.assertPathExists('dir')
553
self.assertPathDoesNotExist('file')
554
self.assertPathExists('dir/file')
533
self.failUnlessExists('dir')
534
self.failIfExists('file')
535
self.failUnlessExists('dir/file')
557
538
class cmd_test_confirm(commands.Command):