Example #1
0
 def setUp(self):
     """
     Set up for each test in the suite.
     """
     if os.path.isdir(self.testdir):
         self.tearDown()
     os.makedirs(U.pj(self.testdir, 'sub'))
     for fp in self.testfiles:
         U.touch(fp)
Example #2
0
def default_input_filename():
    """
    Defines the default input file
    """
    rval = U.pj(os.getenv('HOME'),
                "Dropbox",
                "journal",
                time.strftime("%Y"),
                "WORKLOG")
    return rval
Example #3
0
def test_default_input_filename():
    """
    Make sure workrpt agrees with where we think the default input file
    should be.
    """
    pytest.debug_func()
    home = os.getenv("HOME")
    exp = U.pj(home, "Dropbox", "journal",
               time.strftime("%Y"), "WORKLOG")
    actual = wr.default_input_filename()
    assert exp == actual
Example #4
0
 def test_duplicates(self):
     """
     Hunt for duplicate functions in the .py files
     """
     root = U.bscr_root()
     rpt = ''
     for r, d, f in os.walk(root):
         pylist = [U.pj(r, x) for x in f if x.endswith(".py")]
         for filename in pylist:
             z = self.duplicate_check(filename)
             if z != '':
                 rpt += z
     if rpt != '':
         self.fail(rpt)
Example #5
0
def default_input_filename():
    """
    Defines the default input file
    """
    # rval = "%s/diary/journal/work/%s/WORKLOG" \
    #        % (os.getenv('HOME'), time.strftime('%Y', time.localtime()))
    # rval = time.strftime('/Volumes/ZAPHOD/journal/%Y/WORKLOG',
    #                      time.localtime())
    rval = U.pj(os.getenv('HOME'),
                "Dropbox",
                "journal",
                time.strftime("%Y"),
                "WORKLOG")
    return rval
Example #6
0
    def test_editfile_empty(self):
        """
        fl.editfile('emptyfile', 's', 'foo', 'bar', None)
         => rename emptyfile emptyfile.original, both empty
        """
        fpath = U.pj(self.testdir, 'emptyfile')
        forig = fpath + ".original"
        U.touch(fpath)

        fl.editfile(fpath, 's', 'foo', 'bar', None)

        self.assertEq(True, U.exists(fpath))
        self.assertEq(True, U.exists(forig))
        self.assertEq([], U.contents(fpath))
        self.assertEq([], U.contents(forig))
Example #7
0
 def test_perl_which(self):
     """
     Calling perl_which('Digest::MD5') should get back a string containing
     the same path as sys.__file__
     """
     self.dbgfunc()
     perlinc = pexpect.run("perl -e 'print(\"@INC\");'")
     found = False
     for path in perlinc.split():
         exp = U.pj(path, "Digest", "MD5.pm")
         if glob.glob(exp):
             found = True
             break
     if found:
         self.assertEq(exp, bscr.perl_which('Digest::MD5'))
     else:
         pytest.skip("Digest/MD5 not found in perl @INC")
Example #8
0
 def test_0_pep8(self):
     """
     Check the code in this package for PEP8 conformance.
     """
     # pdb.set_trace()
     pep8 = pexpect.which('pep8')
     if pep8 is None:
         pytest.skip("Pep8 tool not found")
     else:
         root = U.bscr_root()
         for r, d, f in os.walk(root):
             pylist = [U.pj(r, x) for x in f if x.endswith(".py")]
             args = " ".join(pylist)
             if args != '':
                 cmd = "pep8 %s" % args
                 # print cmd
                 result = th.rm_cov_warn(pexpect.run(cmd))
                 self.assertEqual('', result,
                                  "Pep8 report: %s" % result)
Example #9
0
    def test_editfile_delete(self):
        """
        fl.editfile('legit', 's', 'foo', '', None)
        """
        fp = U.pj(self.testdir, U.function_name())
        forig = fp + ".original"
        tdata = ["foo bar",
                 "bar foo",
                 "barfoo",
                 "foobar foo",
                 "loofafool"]
        xdata = [re.sub('^foo', '', z) for z in tdata]
        U.writefile(fp, tdata, newlines=True)

        fl.editfile(fp, 's', '^foo', '', None)

        self.assertEq(True, U.exists(fp))
        self.assertEq(True, U.exists(forig))
        self.assertEq(xdata, U.contents(fp))
        self.assertEq(tdata, U.contents(forig))
Example #10
0
    def test_editfile_suffix(self):
        """
        fl.editfile('legit', 's', 'foo', 'bar', 'old')
        """
        fp = U.pj(self.testdir, U.function_name())
        forig = fp + ".old"
        tdata = ["foo bar",
                 "bar foo",
                 "barfoo",
                 "foobar foo",
                 "loofafool"]
        xdata = [z.replace('foo', 'bar') for z in tdata]
        U.writefile(fp, tdata, newlines=True)

        fl.editfile(fp, 's', 'foo', 'bar', 'old')

        self.assertEq(True, U.exists(fp))
        self.assertEq(True, U.exists(forig))
        self.assertEq(xdata, U.contents(fp))
        self.assertEq(tdata, U.contents(forig))
Example #11
0
    def test_editfile_legit(self):
        """
        fl.editfile('legit', 's', 'foo', 'bar', None)
        """
        fp = U.pj(self.testdir, 'legit')
        forig = fp + ".original"
        tdata = ["foo bar",
                 "bar foo",
                 "barfoo",
                 "foobar foo",
                 "loofafool"]
        xdata = [z.replace('foo', 'bar') for z in tdata]
        U.writefile(fp, tdata, newlines=True)

        fl.editfile(fp, 's', 'foo', 'bar', None)

        self.assertEq(True, U.exists(fp))
        self.assertEq(True, U.exists(forig))
        self.assertEq(xdata, U.contents(fp))
        self.assertEq(tdata, U.contents(forig))