예제 #1
0
    def test_nonempty_subdir_to_nonempty_dir(self):
        """starting dirs & files:
            /tmp/TestGristleDirMerger_source_?/mysubdir
            /tmp/TestGristleDirMerger_source_?/mysubdir/foo.csv
            /tmp/TestGristleDirMerger_dest_???/mysubdir/bar.csv
           should become:
            /tmp/TestGristleDirMerger_source_?
            /tmp/TestGristleDirMerger_source_?/mysubdir/foo.csv
            /tmp/TestGristleDirMerger_dest_???/mysubdir/bar.csv
        """
        source_subdir = os.path.join(self.source_dir, 'mysubdir')
        os.mkdir(source_subdir)
        tt.touch(os.path.join(source_subdir, 'foo.csv'))

        dest_subdir = os.path.join(self.dest_dir, 'mysubdir')
        os.mkdir(dest_subdir)
        tt.touch(os.path.join(dest_subdir, 'bar.csv'))


        self.cmd = """%(pgm)s %(source_dir)s       \
                              %(dest_dir)s         \
                         --match-on-name-only      \
                         --dry-run                 \
                         --log-level debug         \
                   """ % {'pgm': PGM,
                          'source_dir': self.source_dir,
                          'dest_dir':   self.dest_dir}
        self.executor(self.cmd)
        assert 'mysubdir' in os.listdir(self.dest_dir)
        assert 'bar.csv'  in os.listdir(os.path.join(self.dest_dir, 'mysubdir'))
        assert 'mysubdir' in os.listdir(self.source_dir)
        assert 'foo.csv'  in os.listdir(os.path.join(self.source_dir, 'mysubdir'))
예제 #2
0
    def test_nonempty_subdir_to_empty(self):
        """      starting dirs & files:
            /tmp/TestGristleDirMerger_source_?/mysubdir
            /tmp/TestGristleDirMerger_source_?/mysubdir/foo.csv
            /tmp/TestGristleDirMerger_dest_?
                  should become:
            /tmp/TestGristleDirMerger_source_?
            /tmp/TestGristleDirMerger_dest_?/mysubdir/foo.csv
        """
        _ = os.path.join(self.source_dir, 'mysubdir')

        subdir = os.path.join(self.source_dir, 'mysubdir')
        os.mkdir(subdir)
        tt.touch(os.path.join(subdir, 'foo.csv'))

        self.cmd = """%(pgm)s %(source_dir)s       \
                              %(dest_dir)s         \
                         --match-on-name-only      \
                         --log-level debug         \
                         -r                        \
                   """ % {'pgm': PGM,
                          'source_dir': self.source_dir,
                          'dest_dir':   self.dest_dir}
        self.executor(self.cmd)

        print('dest_dir: %s' % self.dest_dir)
        print(os.listdir(self.dest_dir))
        print('dest sub dir: %s' % os.path.join(self.dest_dir, 'mysubdir'))
        print('dest sub contents: ')
        #print os.listdir(os.path.join(self.dest_dir, 'mysubdir'))
        print('is a file? %s' % os.path.isfile(os.path.join(self.dest_dir, 'mysubdir')))

        assert 'mysubdir' in os.listdir(self.dest_dir)
        assert not os.path.exists(self.source_dir)
        assert 'foo.csv'  in os.listdir(os.path.join(self.dest_dir, 'mysubdir'))
 def test_empty_file(self):
     fqfn = pjoin(self.tmp_dir, 'empty.csv')
     test_tools.touch(fqfn)
     cmd = '%s %s --outputformat=parsable' % (pjoin(script_path, 'gristle_determinator'), fqfn)
     runner = envoy.run(cmd)
     print(runner.std_out)
     print(runner.std_err)
     assert runner.status_code == errno.ENODATA
     assert get_value(runner.std_out, 'file_analysis_results', 'main', 'main', 'record_count')  is None
     assert get_value(runner.std_out, 'file_analysis_results', 'main', 'main', 'has_header')    is None
예제 #4
0
 def test_empty_file(self):
     fqfn = pjoin(self.tmp_dir, 'empty.csv')
     test_tools.touch(fqfn)
     cmd = '%s --infiles %s --output-format=parsable' % (pjoin(
         script_path, 'gristle_profiler'), fqfn)
     runner = envoy.run(cmd)
     print(runner.std_out)
     print(runner.std_err)
     assert runner.status_code == errno.ENODATA
     assert get_value(runner.std_out, 'file_analysis_results', 'main',
                      'main', 'record_count') is None
     assert get_value(runner.std_out, 'file_analysis_results', 'main',
                      'main', 'has_header') is None
예제 #5
0
    def test_nonempty_to_empty(self):

        tt.touch(os.path.join(self.source_dir, 'foo.csv'))

        self.cmd = """%(pgm)s %(source_dir)s       \
                              %(dest_dir)s         \
                         --match-on-name-only      \
                         --log-level debug         \
                         -r                        \
                   """ % {'pgm': PGM,
                          'source_dir': self.source_dir,
                          'dest_dir':   self.dest_dir}

        self.executor(self.cmd)
        assert 'foo.csv' in os.listdir(self.dest_dir)
        assert not os.path.exists(self.source_dir)