def test_write_local_fileset_full(self):
        files = set(
            File(f)
            for f in ('dns.2014.Y.mtbl', 'dns.201501.M.mtbl',
                      'dns.20150201.W.mtbl', 'dns.20150208.D.mtbl',
                      'dns.20150209.0000.H.mtbl', 'dns.20150209.0100.X.mtbl',
                      'dns.20150209.0110.m.mtbl'))
        redundant = set(
            File(f)
            for f in ('dns.201401.M.mtbl', 'dns.20150108.W.mtbl',
                      'dns.20150202.D.mtbl', 'dns.20150208.0100.H.mtbl',
                      'dns.20150209.0020.X.mtbl', 'dns.20150209.0109.m.mtbl'))

        fs = Fileset(None, self.td)
        fs.all_local_files = files.union(redundant)
        fs.minimal_local_files = files

        fs.write_local_fileset(minimal=False)

        fileset_path = os.path.join(self.td, 'dns.fileset')
        full_fileset_path = os.path.join(self.td, 'dns-full.fileset')

        self.assertFalse(os.path.exists(fileset_path))
        self.assertTrue(os.path.exists(full_fileset_path))

        fileset = set(File(f.strip()) for f in open(full_fileset_path))

        self.assertItemsEqual(files.union(redundant), fileset)
    def test_prune_obsolete_files_full(self):
        remote_files = set(
            File(f) for f in (
                'dns.2014.Y.mtbl',
                'dns.201401.M.mtbl',
                'dns.20140201.D.mtbl',
                'dns.20140201.0000.H.mtbl',
                'dns.20140201.0100.X.mtbl',
                'dns.20140201.0110.m.mtbl',
                'dns.2015.Y.mtbl',
            ))
        files = set(
            File(f) for f in (
                'dns.2014.Y.mtbl',
                'dns.201401.M.mtbl',
                'dns.20140201.D.mtbl',
                'dns.20140201.0000.H.mtbl',
                'dns.20140201.0100.X.mtbl',
                'dns.20140201.0110.m.mtbl',
                'dns.201501.M.mtbl',
                'dns.20150201.W.mtbl',
                'dns.20150208.D.mtbl',
                'dns.20150209.0000.H.mtbl',
                'dns.20150209.0100.X.mtbl',
                'dns.20150209.0110.m.mtbl',
            ))
        obsolete = set(
            File(f) for f in (
                'dns.2012.Y.mtbl',
                'dns.20130108.W.mtbl',
                'dns.20130202.D.mtbl',
                'dns.20130208.0100.H.mtbl',
                'dns.20130209.0020.X.mtbl',
                'dns.20130209.0109.m.mtbl',
                'dns.20150101.D.mtbl',
                'dns.20150101.0000.H.mtbl',
                'dns.20150101.0100.X.mtbl',
                'dns.20150101.0110.m.mtbl',
            ))

        fs = Fileset(None, self.td)
        fs.all_local_files = files.union(obsolete)
        fs.minimal_local_files = files.union(obsolete)
        fs.remote_files = remote_files
        fs.prune_obsolete_files(minimal=False)

        self.assertItemsEqual(fs.all_local_files, files)
        self.assertItemsEqual(fs.minimal_local_files, files)
        self.assertItemsEqual(fs.remote_files, remote_files)
        self.assertItemsEqual(fs.pending_deletions, obsolete)
    def test_missing_files(self):
        files = set(
            File(f)
            for f in ('dns.2014.Y.mtbl', 'dns.201501.M.mtbl',
                      'dns.20150201.W.mtbl', 'dns.20150208.D.mtbl',
                      'dns.20150209.0000.H.mtbl', 'dns.20150209.0100.X.mtbl',
                      'dns.20150209.0110.m.mtbl'))
        missing = set(
            File(f)
            for f in ('dns.2012.Y.mtbl', 'dns.20130108.W.mtbl',
                      'dns.20130202.D.mtbl', 'dns.20130208.0100.H.mtbl',
                      'dns.20130209.0020.X.mtbl', 'dns.20130209.0109.m.mtbl'))

        fs = Fileset(None, self.td)
        fs.all_local_files = set(files)
        fs.minimal_local_files = set(files)
        fs.remote_files = files.union(missing)

        self.assertItemsEqual(fs.missing_files(), missing)
    def test_prune_redundant_files(self):
        files = set(
            File(f)
            for f in ('dns.2014.Y.mtbl', 'dns.201501.M.mtbl',
                      'dns.20150201.W.mtbl', 'dns.20150208.D.mtbl',
                      'dns.20150209.0000.H.mtbl', 'dns.20150209.0100.X.mtbl',
                      'dns.20150209.0110.m.mtbl'))
        redundant = set(
            File(f)
            for f in ('dns.201401.M.mtbl', 'dns.20150108.W.mtbl',
                      'dns.20150202.D.mtbl', 'dns.20150208.0100.H.mtbl',
                      'dns.20150209.0020.X.mtbl', 'dns.20150209.0109.m.mtbl'))

        fs = Fileset(None, self.td)
        fs.minimal_local_files = files.union(redundant)
        fs.prune_redundant_files()

        self.assertItemsEqual(fs.minimal_local_files, files)
        self.assertItemsEqual(fs.pending_deletions, redundant)