Example #1
0
def test_diff_match_pxr(tmpdir, fx_match):
    """
    Test 'fl diff FILENAME' when a prefix match exists
    """
    pytest.debug_func()
    with U.Chdir(tmpdir.strpath):
        cmd = "{} diff {}".format(U.script_location("fl"),
                                  fx_match.mrpm1.basename)
        got = pexpect.run(cmd).split("\n")
        assert fx_match.mrpm1_diff_exp == [_.rstrip() for _ in got]

        cmd = "{} diff {}".format(U.script_location("fl"),
                                  fx_match.mrpm2.basename)
        got = pexpect.run(cmd).split("\n")
        assert fx_match.mrpm2_diff_exp == [_.rstrip() for _ in got]
Example #2
0
def test_fx_help():
    """
    Verify that 'fx --help' does the right thing
    """
    pytest.debug_func()
    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:
        assert exp_s in result
Example #3
0
 def test_ascii(self):
     """
     Run ascii and see if its output matches what is expected.
     """
     ascii = U.script_location("ascii")
     result = pexpect.run(ascii)
     self.assertEq("\r\n".join(self.exp), result)
Example #4
0
    def test_diff(self):
        """
        Test diff
        """
        with util.Chdir("fl_tests"):
            util.writefile('mrpm1', ['this is a test file\n'])
            util.writefile('mrpm2', ['this is another test file\n'])
            util.writefile('mrpm1.2009-10-01', ['copy of test file\n'])
            util.writefile('old/mrpm2.2009-08-31',
                           ['copy of another test file\n'])

            expected = ['diff ./mrpm1.2009-10-01 mrpm1\r',
                        '1c1\r',
                        '< copy of test file\r',
                        '---\r',
                        '> this is a test file\r',
                        '']
            cmd = util.script_location("fl")
            got = pexpect.run("%s diff mrpm1" % cmd).split("\n")
            self.assertEqual(expected, got)

            expected = ['diff ./old/mrpm2.2009-08-31 mrpm2\r',
                        '1c1\r',
                        '< copy of another test file\r',
                        '---\r',
                        '> this is another test file\r',
                        '']
            got = pexpect.run("%s diff mrpm2" % cmd).split("\n")
            self.assertEqual(expected, got)
Example #5
0
    def test_example(self):
        """
        Example calc session
        """
        calc = U.script_location("calc")
        S = pexpect.spawn(calc)
        # S.logfile = sys.stdout
        S.expect("> ")

        S.sendline("7 + 12")
        S.expect("> ")

        assert("19" in S.before)

        S.sendline("7.988 + 28.576")
        S.expect("> ")

        assert("36.564000" in S.before)

        S.sendline("\"zap\" * 2")
        S.expect("> ")

        assert("zapzap" in S.before)

        S.sendline("exit()")
        S.expect(pexpect.EOF)
        S.close()
Example #6
0
 def test_final_newline(self):
     """
     Run ascii and verify output ends with a newline
     """
     # pdb.set_trace()
     ascii = U.script_location("ascii")
     result = pexpect.run(ascii)
     self.assertTrue(result.endswith("\n"),
                     "ascii output should end with newline")
Example #7
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)))
Example #8
0
def test_named_input(tmpdir, fx_data):
    """
    Handle both input on stdin as well as input from a named file.
    """
    pytest.debug_func()
    tfile = tmpdir.join("testdata")
    tfile.write("\n".join(fx_data.tdata) + "\n")
    script = U.script_location("align")
    fx_data.result = pexpect.run("{} {}".format(script, tfile.strpath))
Example #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)))
Example #10
0
 def test_fl_help(self):
     """
     'fl help' should get help output
     """
     cmd = util.script_location("fl")
     result = pexpect.run('%s help' % cmd)
     self.assertFalse('Traceback' in result)
     for f in [x for x in dir(fl) if x.startswith('bscr_')]:
         subc = f.replace('bscr_', '')
         self.assertTrue('%s - ' % subc in result)
Example #11
0
def test_fl_help_pxr():
    """
    'fl help' should get help output
    """
    pytest.debug_func()
    cmd = util.script_location("fl")
    result = pexpect.run('{} help'.format(cmd))
    assert "Traceback" not in result
    for f in [x for x in dir(fl) if x.startswith('bscr_')]:
        subc = f.replace('bscr_', '')
        assert "{} - ".format(subc) in result
Example #12
0
def test_command_line():
    """
    Running the command with no arguments should get help output
    """
    pytest.debug_func()
    thisone = util.script_location("fl")

    result = pexpect.run(thisone)
    assert "Traceback" not in result
    assert "diff" in result
    assert "save" in result
    assert "times" in result
Example #13
0
    def test_command_line(self):
        """
        Running the command with no arguments should get help output
        """
        thisone = util.script_location("fl")

        # print(thisone)
        result = pexpect.run(thisone)
        self.assertNotIn("Traceback", result)
        self.assertIn("diff", result)
        self.assertIn("save", result)
        self.assertIn("times", result)
Example #14
0
    def test_named_input(self):
        """
        Handle both input on stdin as well as input from a named file.
        """
        tfilename = 'testdata'
        f = open(tfilename, 'w')
        for line in self.tdata:
            f.write(line + "\n")
        f.close()

        script = U.script_location("align")
        x = th.rm_cov_warn(pexpect.run("%s %s" % (script, tfilename)))
        self.assertEq(self.exp, x)
Example #15
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)))
Example #16
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)))
Example #17
0
 def test_digit_alignment(self):
     """
     Words that contain valid numeric specifications should be right
     aligned. Words containing non-numeric values should be left aligned.
     """
     script = U.script_location("align")
     S = pexpect.spawn(script)
     S.setecho(False)
     for line in self.tdata:
         S.sendline(line)
     S.send("\004")
     S.expect(pexpect.EOF)
     x = th.rm_cov_warn(S.before)
     S.close()
     self.assertEq(self.exp, x)
Example #18
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)))
Example #19
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)))
Example #20
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)))
Example #21
0
def test_xclean_help():
    """
    Verify that 'xclean --help' does the right thing
    """
    pytest.debug_func()
    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:
        assert line in actual
Example #22
0
    def test_revert(self):
        """
        Test revert
        """
        with util.Chdir("fl_tests"):
            util.writefile('mrpm1', ['this is a test file\n'])
            util.writefile('mrpm2', ['this is another test file\n'])
            util.writefile('mrpm1.2009-10-01', ['reverted\n'])
            util.writefile('old/mrpm2.2009-08-31',
                           ['REVERTED\n'])

            fl = util.script_location("fl")
            os.system('%s revert mrpm1' % fl)
            assert(os.path.exists('mrpm1.new'))
            assert(os.path.exists('mrpm1'))
            assert(not os.path.exists('mrpm1.2009-10-01'))
            assert(util.contents('mrpm1') == ['reverted'])

            os.system('%s revert mrpm2' % fl)
            assert(os.path.exists('mrpm2.new'))
            assert(os.path.exists('mrpm2'))
            assert(not os.path.exists('old/mrpm2.2009-08-31'))
            assert(util.contents('mrpm2') == ['REVERTED'])