Example #1
0
  def test_filter_files_by_patterns(self):
    #Assuming <../tests/foo> is <../User/>
    base_path = Helper.join_path((self.base_path, 'foo'))

    os.makedirs(Helper.join_path((self.base_path, 'foo', 'bar')))
    open(Helper.join_path((base_path, 'foo.txt')), 'a').close()
    open(Helper.join_path((base_path, 'bar.rb')), 'a').close()
    open(Helper.join_path((base_path, 'bar', 'foo.txt')), 'a').close()
    open(Helper.join_path((base_path, 'bar', 'foo.py')), 'a').close()


    files = Helper.get_files(base_path)
    patterns = Helper.parse_patterns(['.rb', '.py'], base_path)
    expected = sorted([
      Helper.join_path((base_path, 'bar.rb')),
      Helper.join_path((base_path, 'bar', 'foo.py'))
    ])
    filtered_files = sorted(Helper.filter_files_by_patterns(files, patterns))

    self.assertEqual(len(filtered_files), 2)
    self.assertListEqual(filtered_files, expected)

    patterns = Helper.parse_patterns(['bar/foo.txt'], base_path)
    expected = [Helper.join_path((base_path, 'bar', 'foo.txt'))]
    filtered_files = sorted(Helper.filter_files_by_patterns(files, patterns))

    self.assertEqual(len(filtered_files), 1)
    self.assertListEqual(filtered_files, expected)

    shutil.rmtree(Helper.join_path((self.base_path, 'foo')))
Example #2
0
    def test_filter_files_by_patterns(self):
        #Assuming <../tests/foo> is <../User/>
        base_path = Helper.join_path((self.base_path, 'foo'))

        os.makedirs(Helper.join_path((self.base_path, 'foo', 'bar')))
        open(Helper.join_path((base_path, 'foo.txt')), 'a').close()
        open(Helper.join_path((base_path, 'bar.rb')), 'a').close()
        open(Helper.join_path((base_path, 'bar', 'foo.txt')), 'a').close()
        open(Helper.join_path((base_path, 'bar', 'foo.py')), 'a').close()

        files = Helper.get_files(base_path)
        patterns = Helper.parse_patterns(['.rb', '.py'], base_path)
        expected = sorted([
            Helper.join_path((base_path, 'bar.rb')),
            Helper.join_path((base_path, 'bar', 'foo.py'))
        ])
        filtered_files = sorted(
            Helper.filter_files_by_patterns(files, patterns))

        self.assertEqual(len(filtered_files), 2)
        self.assertListEqual(filtered_files, expected)

        patterns = Helper.parse_patterns(['bar/foo.txt'], base_path)
        expected = [Helper.join_path((base_path, 'bar', 'foo.txt'))]
        filtered_files = sorted(
            Helper.filter_files_by_patterns(files, patterns))

        self.assertEqual(len(filtered_files), 1)
        self.assertListEqual(filtered_files, expected)

        shutil.rmtree(Helper.join_path((self.base_path, 'foo')))
Example #3
0
  def test_parse_patterns(self):
    patterns = ['.txt', '.py', 'foo', 'bar.py']
    expected = sorted([
      '.txt',
      '.py',
      Helper.join_path((self.base_path, 'foo')),
      Helper.join_path((self.base_path, 'bar.py'))
    ])

    result = sorted(Helper.parse_patterns(patterns, self.base_path))
    self.assertListEqual(result, expected)

    patterns = sorted(['.foo', '.DStore', '.file.name'])
    expected = sorted(['.foo', '.DStore', Helper.join_path((self.base_path, '.file.name'))])
    result = sorted(Helper.parse_patterns(patterns, self.base_path))
    self.assertListEqual(result, expected)
Example #4
0
    def test_parse_patterns(self):
        patterns = ['.txt', '.py', 'foo', 'bar.py']
        expected = sorted([
            '.txt', '.py',
            Helper.join_path((self.base_path, 'foo')),
            Helper.join_path((self.base_path, 'bar.py'))
        ])

        result = sorted(Helper.parse_patterns(patterns, self.base_path))
        self.assertListEqual(result, expected)

        patterns = sorted(['.foo', '.DStore', '.file.name'])
        expected = sorted([
            '.foo', '.DStore',
            Helper.join_path((self.base_path, '.file.name'))
        ])
        result = sorted(Helper.parse_patterns(patterns, self.base_path))
        self.assertListEqual(result, expected)