#!/usr/bin/env python3
"""
Rename (rn.py) test program.

Copyright (C) 2015 Jose M. Casarejos

This program 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.

This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

You may contact the author of the program at: <rn-program at mundo-r dot com>

Create a testing directory testdir to be used by test_rn.py
Delete testing directory at exit
"""
import os
import sys
import shutil
# create test directory
#
# testdir
#   |
#   |-- members: Graham Chapman, John Cleese, Terry Gilliam, Eric Idle,
#   |            Terry Jones, Michael Palin
#   |
#   |-- movies: movies.txt
#   |      |
#   |      |-- Flying Circus
#   |      |-- Life of Brian
#   |      |-- The Holy Grail
#   |                |- Arthur, Lancelot, Patsy, Robin, Galahad
#   |-- special: *asterisk, ?question, [brackets]
testdir = ['members', 'movies']
members = ['Graham Chapman', 'John Cleese', 'Terry Gilliam', 'Eric Idle',
           'Terry Jones', 'Michael Palin']
movies = ['Flying Circus', 'Life of Brian', 'The Holy Grail']
characters = ['Arthur', 'Lancelot', 'Patsy', 'Robin', 'Galahad']
os.mkdir('testdir')
os.chdir('testdir')
for dir in testdir:
    os.mkdir(dir)
os.chdir('members')
for file in members:
    open(file, 'a').close()
os.chdir(os.pardir)
os.chdir('movies')
open('movies.txt', 'a').close
for dir in movies:
    os.mkdir(dir)
os.chdir('The Holy Grail')
for file in characters:
    open(file, 'a').close()
os.chdir(os.pardir)
os.chdir(os.pardir)
os.mkdir('special')
os.chdir('special')
if sys.platform.startswith('win'):
    members = ['asterisk', 'question', '[brackets]']
else:
    members = ['*asterisk', '?question', '[brackets]']
for file in members:
    open(file, 'a').close()
os.chdir(os.pardir)
os.chdir(os.pardir)
# execute tests
os.system('py.test test_rn.py')
# delete test directory
shutil.rmtree('testdir')
