def test_load_mod_newer(self):
        mod_filename = self.make_file('',
                                      'filename', [
                                          '# Name: Mod Name',
                                          '# Categories: cat1',
                                          '# testing',
                                          '',
                                          'SparkServiceWhatever',
                                      ],
                                      mtime=84)
        mod = ModFile(42)
        mod.mod_title = 'Testing Mod'
        mod.mod_desc = ['overwrite']
        cache_filename = os.path.join(self.tmpdir, 'cache')
        cache = FileCache(ModFile, cache_filename)
        cache.mapping[mod_filename] = mod
        cache.save()

        # Reload from disk, just in case anything's weird
        cache = FileCache(ModFile, cache_filename)
        dirinfo = DirInfo('/tmp/doesnotexist', self.tmpdir, ['filename'])
        loaded_mod = cache.load(dirinfo,
                                'filename',
                                valid_categories=self.valid_cats)
        self.assertIsNotNone(loaded_mod)
        self.assertEqual(loaded_mod.status, ModFile.S_UPDATED)
        self.assertIn(mod_filename, cache)
        self.assertEqual(loaded_mod.mod_desc, ['testing'])
 def new_dirinfo(self, path, filenames):
     """
     Creates a new DirInfo object based on the given `path`, with the
     specified list of `filenames`.
     """
     full_path = os.path.join(self.base_dir, path)
     return DirInfo(self.base_dir, full_path, filenames)
 def test_load_readme_not_found(self):
     """
     Ditto above
     """
     readme = Readme(0)
     readme.mapping['(default)'].append('Testing Readme')
     filename = os.path.join(self.tmpdir, 'cache')
     cache = FileCache(Readme, filename)
     cache.mapping['filename'] = readme
     cache.save()
     dirinfo = DirInfo(self.tmpdir, '', ['filename'])
     with self.assertRaises(FileNotFoundError) as cm:
         cache.load(dirinfo, 'filename')
    def test_load_readme_new_file(self):
        readme_filename = self.make_file('', 'filename', ['testing'], mtime=42)
        cache_filename = os.path.join(self.tmpdir, 'cache')
        cache = FileCache(Readme, cache_filename)
        cache.save()

        # Reload from disk, just in case anything's weird
        cache = FileCache(Readme, cache_filename)
        dirinfo = DirInfo('/tmp/doesnotexist', self.tmpdir, ['filename'])
        loaded_readme = cache.load(dirinfo, 'filename')
        self.assertIsNotNone(loaded_readme)
        self.assertEqual(loaded_readme.status, ModFile.S_NEW)
        self.assertIn(readme_filename, cache)
        self.assertEqual(loaded_readme.mapping['(default)'], ['testing'])
 def test_load_mod_not_found(self):
     """
     Not actually sure if this is what we should do here; for now we're
     just letting the eventual file open fail.  Given that while running
     we should only be getting filenames that have come from os.walk(),
     this shouldn't be a big deal anyway, really.
     """
     mod = ModFile(0)
     mod.mod_title = 'Testing Mod'
     filename = os.path.join(self.tmpdir, 'cache')
     cache = FileCache(ModFile, filename)
     cache.mapping['filename'] = mod
     cache.save()
     dirinfo = DirInfo(self.tmpdir, '', ['filename'])
     with self.assertRaises(FileNotFoundError) as cm:
         cache.load(dirinfo, 'filename')
    def test_load_mod_same_mtimes(self):
        mod_filename = self.make_file('', 'filename', ['testing'], mtime=42)
        mod = ModFile(42)
        mod.mod_title = 'Testing Mod'
        mod.mod_desc = ['no overwrite']
        cache_filename = os.path.join(self.tmpdir, 'cache')
        cache = FileCache(ModFile, cache_filename)
        cache.mapping[mod_filename] = mod
        cache.save()

        # Reload from disk, just in case anything's weird
        cache = FileCache(ModFile, cache_filename)
        dirinfo = DirInfo('/tmp/doesnotexist', self.tmpdir, ['filename'])
        loaded_mod = cache.load(dirinfo, 'filename')
        self.assertIsNotNone(loaded_mod)
        self.assertEqual(loaded_mod.status, ModFile.S_CACHED)
        self.assertIn(mod_filename, cache)
        self.assertEqual(loaded_mod.mod_desc, ['no overwrite'])