Exemple #1
0
 def test_psys_quiet(self):
     """
     Test routine psys with dryrun False and quiet True.
     """
     with U.Chdir(self.testdir):
         with th.StdoutExcursion() as getval:
             v = optparse.Values({'dryrun': False, 'quiet': True})
             fx.psys('ls', v)
             actual = getval()
     expected = "a.xyzzy\nb.xyzzy\nc.xyzzy\ntmpfile\n"
     self.assertEqual(expected, actual,
                      "%s\n   !=\n%s" %
                      (U.lquote(expected), U.lquote(actual)))
Exemple #2
0
 def test_calc_help(self):
     """
     Verify that 'calc --help' does the right thing
     """
     cmd = U.script_location("calc")
     result = pexpect.run("%s --help" % cmd)
     nexp = "Traceback"
     self.assertFalse(nexp in result,
                      "Not expecting '%s' in %s" %
                      (nexp, U.lquote(result)))
     exp = "Usage: calc [options]"
     self.assertTrue(exp in result,
                     "Expected '%s' in %s" %
                     (exp, U.lquote(result)))
Exemple #3
0
 def test_bscr_version(self):
     """
     Test 'bscr version'
     """
     self.dbgfunc()
     cmd = "bscr version -v"
     result = th.rm_cov_warn(pexpect.run(cmd))
     self.assertTrue("Traceback" not in result,
                     "Not expecting 'Traceback' in %s" %
                     U.lquote(result))
     self.assertTrue("Backscratcher version" in result)
     self.assertEqual(2, len(result.split("\n")),
                      "Expected only 1 newlines in %s" %
                      U.lquote(result))
Exemple #4
0
 def test_align_help(self):
     """
     Verify that 'align --help' does the right thing
     """
     cmd = U.script_location("align")
     result = pexpect.run("%s --help" % cmd)
     nexp = "Traceback"
     self.assertFalse(nexp in result,
                      "Not expecting '%s' in %s" %
                      (nexp, U.lquote(result)))
     exp = "Align columns from input"
     self.assertTrue(exp in result,
                     "Expected '%s' in %s" %
                     (exp, U.lquote(result)))
Exemple #5
0
 def test_usage(self):
     """
     Test the Usage routine.
     """
     exp = '\n'
     exp += '    fx [-n] -c <command> <files> (% in the command becomes'
     exp += ' filename)\n'
     exp += '            -e s/old/new/ <files> (rename file old to new'
     exp += ' name)\n'
     exp += '            -i low:high -c <command> (% ranges from low to'
     exp += ' high-1)\n            '
     actual = fx.Usage()
     self.assertEqual(actual, exp,
                      "%s != %s" %
                      (U.lquote(repr(actual)), U.lquote(repr(exp))))
Exemple #6
0
 def test_mag_help(self):
     """
     Verify that 'mag --help' does the right thing
     """
     cmd = U.script_location("mag")
     result = pexpect.run("%s --help" % cmd)
     exp = [
         "Usage: mag [-b] <number>",
         "Report the order of magnitude of <number>",
         "Options:",
         "-h, --help    show this help message and exit",
         "-b, --binary  div=1024 rather than 1000",
     ]
     self.assertTrue("Traceback" not in result, "Traceback not expected in %s" % U.lquote(result))
     for item in exp:
         self.assertTrue(item in result, "Expected '%s' in %s" % (item, U.lquote(result)))
Exemple #7
0
 def test_lquote(self):
     """
     Routine lquote() wraps its input in triple quotes with newlines
     """
     testdata = "The quick brown fox jumps over the lazy dog"
     self.assertEqual('"""\n%s\n"""' % testdata,
                      U.lquote(testdata))
Exemple #8
0
 def test_fx_help(self):
     """
     Verify that 'fx --help' does the right thing
     """
     # pdb.set_trace()
     exp_l = ["Usage:",
              "fx [-n] -c <command> <files> (% in the command becomes" +
              " filename)",
              "-e s/old/new/ <files> (rename file old to new name)",
              "-i low:high -c <command> (% ranges from low to high-1)",
              "Options:",
              "",
              "-c CMD, --command=CMD",
              "command to apply to all arguments",
              "-d, --debug           run under the debugger",
              "-e EDIT, --edit=EDIT  file rename expression applied to " +
              "all arguments",
              " -i IRANGE, --integer=IRANGE",
              "low:high -- generate range of numbers",
              "-n, --dry-run         dryrun or execute",
              "-q, --quiet           don't echo commands, just run them",
              "-x, --xargs           batch input from stdin into command" +
              " lines like xargs",
              ]
     script = U.script_location("fx")
     result = pexpect.run("%s --help" % script)
     for exp_s in exp_l:
         self.assertTrue(exp_s in result,
                         "Expected '%s' in %s" %
                         (exp_s, U.lquote(result)))
Exemple #9
0
 def test_jcal_help(self):
     """
     Verify that 'jcal --help' does the right thing
     """
     cmd = U.script_location("jcal")
     result = pexpect.run("%s help" % cmd)
     exp = "help - show this list"
     self.assertTrue(exp in result, "Expected '%s' in %s" %
                     (exp, U.lquote(result)))
Exemple #10
0
 def test_ascii_help(self):
     """
     Run 'ascii --help' and validate the output
     """
     cmd = U.script_location("ascii")
     result = pexpect.run("%s --help" % cmd)
     exp = "Display ASCII collating sequence"
     self.assertTrue(exp in result, "Expected '%s' in %s" %
                     (exp, U.lquote(result)))
Exemple #11
0
 def fl_edit_flawed(self, cmd, exp):
     """
     Attempt to run an 'fl edit' command with something missing
     """
     result = pexpect.run(cmd)
     self.assertFalse("Traceback" in result,
                      "Traceback not expected in %s" % result)
     self.assertTrue(exp in result,
                     "\nExpected '%s' in \n%s" %
                     (exp, util.lquote(result)))
Exemple #12
0
    def test_hexdump(self):
        """
        Routine hexdump() reads one file and hexdumps it to another.
        """
        exp = "\n".join([
            " 54 77 61 73  20 62 72 69  6c 6c 69 67  20 61 6e 64    " +
            "Twas bri llig and",
            " 20 74 68 65  20 73 6c 69  74 68 65 20  74 6f 76 65    " +
            " the sli the tove",
            " 73 0a 44 69  64 20 67 79  72 65 20 61  6e 64 20 67    "
            "s.Did gy re and g",
            " 69 6d 62 6c  65 20 72 6f  75 6e 64 20  74 68 65 20    "
            "imble ro und the ",
            " 77 61 62 65  0a 41 6c 6c  20 6d 69 6d  73 79 20 77    "
            "wabe.All  mimsy w",
            " 65 72 65 20  74 68 65 20  62 6f 72 6f  67 72 6f 76    "
            "ere the  borogrov",
            " 65 73 0a 41  6e 64 20 74  68 65 20 6d  6f 6d 65 20    "
            "es.And t he mome ",
            " 72 61 74 68  73 20 6f 75  74 67 72 61  62 65 0a       "
            "raths ou tgrabe. ",
            ""
            ])

        q = sio("\n".join(["Twas brillig and the slithe toves",
                           "Did gyre and gimble round the wabe",
                           "All mimsy were the borogroves",
                           "And the mome raths outgrabe\n"]))
        z = sio()
        hd.hexdump(q, z)
        result = z.getvalue()
        z.close()
        q.close()

        self.assertEqual(exp, result,
                         "%s != %s" % (U.lquote(repr(exp)),
                                       U.lquote(repr(result))))
Exemple #13
0
 def test_odx_help(self):
     """
     Verify that 'odx --help' does the right thing
     """
     exp = [
         "Usage: odx {0<octal-value>|<decimal-value>|0x<hex-value>} ...",
         "    report each argument in octal, decimal, and hex format",
         "",
         "Options:",
         "  -h, --help   show this help message and exit",
         "  -d, --debug  run under debugger",
     ]
     cmd = U.script_location("odx")
     actual = pexpect.run("%s --help" % cmd)
     for line in exp:
         self.assertTrue(line in actual, "Expected '%s' in %s" % (line, U.lquote(actual)))
Exemple #14
0
 def test_perrno_help(self):
     """
     Verify that 'perrno --help' does the right thing
     """
     exp = [
         "Usage: perrno {-a|--all|number ...|errname ...}",
         "    report errno numeric and string values",
         "",
         "Options:",
         "  -h, --help   show this help message and exit",
         "  -a, --all    list all errno values",
         "  -d, --debug  run the debugger",
     ]
     cmd = U.script_location("perrno")
     actual = pexpect.run("%s --help" % cmd)
     for line in exp:
         self.assertTrue(line in actual, "Expected '%s' in %s" % (line, U.lquote(actual)))
Exemple #15
0
 def test_xclean_help(self):
     """
     Verify that 'xclean --help' does the right thing
     """
     exp = ["Usage:",
            "    xclean - remove files whose names match a regexp",
            "",
            "Options:",
            "  -h, --help            show this help message and exit",
            "  -d, --debug           run under the debugger",
            "  -n, --dry-run         just report",
            "  -p PATTERN, --pattern=PATTERN",
            "                        file matching regexp",
            "  -r, --recursive       whether to descend directories",
            ]
     cmd = U.script_location("xclean")
     actual = pexpect.run("%s --help" % cmd)
     for line in exp:
         self.assertTrue(line in actual,
                         "Expected '%s' in %s" %
                         (line, U.lquote(actual)))