#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# For copyright information, see AUTHORS.
#
# Déjà Dup is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Déjà Dup is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.

# Test whether we correctly include/exclude complicated file hierarchies

import sys
sys.path.insert(0, sys.path[0]+'/..')
import base
import ldtp
import os

def test():
  # Backup the tree data set
  base.setup()
  base.backup_simple(backend='file',
                     includes=['data/tree/a', 'data/tree/a/b/c', 'data/tree/one/two', 'data/tree/one/two/three/four'],
                     excludes=['data/tree/a/b', 'data/tree/a/b/c/d', 'data/tree/one', 'data/tree/one/two/three'])
  # Restore it
  restoredir = base.get_temp_name('restore')
  base.restore_simple(restoredir)
  # And check that the right leaves are there
  root = os.path.join(restoredir, os.path.normpath(sys.path[0])[1:], 'data/tree')
  def present(path):
    assert os.path.exists(os.path.join(root, path)), os.path.join(root, path)
  def absent(path):
    assert not os.path.exists(os.path.join(root, path)), os.path.join(root, path)
  present('a/leaf')
  present('a/b/c/leaf')
  present('one/two/leaf')
  present('one/two/three/four/leaf')
  absent('a/b/leaf')
  absent('a/b/c/d/leaf')
  absent('one/leaf')
  absent('one/two/three/leaf')

base.run(test)
