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

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

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

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

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

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

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

    self.create_folder(Utils.join_path(self.base_path, 'foo', 'bar'))
    open(Utils.join_path(base_path, 'foo.txt'), 'a').close()
    open(Utils.join_path(base_path, 'bar.rb'), 'a').close()
    open(Utils.join_path(base_path, 'bar', 'foo.txt'), 'a').close()
    open(Utils.join_path(base_path, 'bar', 'foo.py'), 'a').close()
    open(Utils.join_path(base_path, 'bar', 'main.go'), 'a').close()
    open(Utils.join_path(base_path, 'bar', 'other.go'), 'a').close()

    files = Utils.get_files(base_path)
    patterns = Utils.parse_patterns([
      '.rb',
      '.py',
      Utils.join_path('bar', '*.go')
    ], base_path)

    expected = sorted([
      Utils.join_path(base_path, 'bar.rb'),
      Utils.join_path(base_path, 'bar', 'foo.py'),
      Utils.join_path(base_path, 'bar', 'main.go'),
      Utils.join_path(base_path, 'bar', 'other.go')
    ])

    filtered_files = sorted(Utils.filter_files_by_patterns(files, patterns))

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

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

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

    self.delete_folder(Utils.join_path(self.base_path, 'foo'))
Esempio n. 3
0
    def test_filter_files_by_patterns(self):
        #Assuming <../tests/foo> is <../User/>
        base_path = Utils.join_path(self.base_path, 'foo')

        self.create_folder(Utils.join_path(self.base_path, 'foo', 'bar'))
        open(Utils.join_path(base_path, 'foo.txt'), 'a').close()
        open(Utils.join_path(base_path, 'bar.rb'), 'a').close()
        open(Utils.join_path(base_path, 'bar', 'foo.txt'), 'a').close()
        open(Utils.join_path(base_path, 'bar', 'foo.py'), 'a').close()
        open(Utils.join_path(base_path, 'bar', 'main.go'), 'a').close()
        open(Utils.join_path(base_path, 'bar', 'other.go'), 'a').close()

        files = Utils.get_files(base_path)
        patterns = Utils.parse_patterns(
            ['.rb', '.py', Utils.join_path('bar', '*.go')], base_path)

        expected = sorted([
            Utils.join_path(base_path, 'bar.rb'),
            Utils.join_path(base_path, 'bar', 'foo.py'),
            Utils.join_path(base_path, 'bar', 'main.go'),
            Utils.join_path(base_path, 'bar', 'other.go')
        ])

        filtered_files = sorted(Utils.filter_files_by_patterns(
            files, patterns))

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

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

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

        self.delete_folder(Utils.join_path(self.base_path, 'foo'))