File: test_ignores.py

package info (click to toggle)
couchapp 1.0.1%2Bgit20140213%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 968 kB
  • ctags: 405
  • sloc: python: 3,278; sh: 53; makefile: 22
file content (74 lines) | stat: -rw-r--r-- 2,556 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
#
# Copyright 2008,2009 Benoit Chesneau <benoitc@e-engura.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import unittest2 as unittest
import tempfile
import os
from shutil import rmtree

from couchapp.localdoc import LocalDoc as doc
import json


class IgnoresTests(unittest.TestCase):

    def setUp(self):
        # Create a temp dir for the tests to run in
        self.tmp_dir = tempfile.mkdtemp()
        # Define some test data
        self.testdata = {'CVS': True, "dontignorethisCVS": False,
                         "ignore_me": True, "but_don't_ignore_me": False}
        # Create the ignores file
        self.ignores = ["^CVS", "ignore_me"]
        f = open(os.path.join(self.tmp_dir, '.couchappignore'), 'w')
        json.dump(self.ignores, f)
        f.close()

        # Make a UI and a doc instance for the tests
        self.doc = doc(self.tmp_dir)

        # I could write these files to the temp area, but that seems
        # unnecessary since the unit test doesn't interact with the file
        # system other than to make the .couchappignore file.
        #for i in self.testdata.keys():
        #   open(os.path.join(self.tmp_dir, i), 'w').close()

    def tearDown(self):
        # Clear up temp dir and the files it contains
        rmtree(self.tmp_dir)

    def testLoadIgnores(self):
        """
        If the code works the doc should have a data member containing a list
        of the regexps to ignore, and this list should be the same as the list
        stored in self.ignores and used in setUp to create the .couchappignore
        file.
        """
        assert self.doc.ignores == self.ignores

    def testIgnore(self):
        """
        Run through the test data and check that the doc would treat it
        appropriately were it a file/directory the doc was uploading.

        Really this test checks the re module...
        """
        for i in self.testdata.keys():
            assert self.doc.check_ignore(i) == self.testdata[i]

if __name__ == '__main__':
    unittest.main()