Move test_glob out of ThriftTest and into its own test.

Summary:
I would like to to test more inputs for `glob()` with different characteristics.
I think this would be more logically organized when divided across a number of
test methods in a single `GlobTest` class.

This revision does a straight move of the eixsting `test_glob()` method without
introducing any new test cases.

Reviewed By: chadaustin

Differential Revision: D7741506

fbshipit-source-id: 141341d74265f3949ed7523f40a56f98d95ee13e
This commit is contained in:
Michael Bolin 2018-04-26 13:47:01 -07:00 committed by Facebook Github Bot
parent be469fca31
commit a24cffb99b
2 changed files with 69 additions and 33 deletions

View File

@ -0,0 +1,68 @@
#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from facebook.eden.ttypes import EdenError
from .lib import testcase
@testcase.eden_repo_test
class GlobTest(testcase.EdenRepoTest):
def populate_repo(self) -> None:
self.repo.write_file('hello', 'hola\n')
self.repo.write_file('README', 'docs\n')
self.repo.write_file('adir/file', 'foo!\n')
self.repo.write_file('bdir/file', 'bar!\n')
self.repo.symlink('slink', 'hello')
self.commit1 = self.repo.commit('Initial commit.')
self.repo.write_file('bdir/file', 'bar?\n')
self.repo.write_file('cdir/subdir/new.txt', 'and improved')
self.repo.remove_file('README')
self.commit2 = self.repo.commit('Commit 2.')
def setUp(self) -> None:
super().setUp()
self.client = self.get_thrift_client()
self.client.open()
self.addCleanup(self.client.close)
def test_glob(self) -> None:
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['a*/file'])
)
self.assertCountEqual(
['adir/file', 'bdir/file'],
self.client.glob(self.mount, ['**/file'])
)
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/*'])
)
self.assertCountEqual(
['adir/file', 'bdir/file'],
self.client.glob(self.mount, ['adir/*', '**/file']),
msg='De-duplicate results from multiple globs'
)
self.assertEqual(['hello'], self.client.glob(self.mount, ['hello']))
self.assertEqual(
[],
self.client.glob(self.mount, ['hell']),
msg="No accidental substring match"
)
self.assertEqual(['hello'], self.client.glob(self.mount, ['hel*']))
self.assertEqual(['adir'], self.client.glob(self.mount, ['ad*']))
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/**/*'])
)
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/**'])
)
with self.assertRaises(EdenError) as ctx:
self.client.glob(self.mount, ['adir['])
self.assertIn('unterminated bracket sequence', str(ctx.exception))

View File

@ -11,7 +11,7 @@ import binascii
import hashlib
import os
from facebook.eden.ttypes import EdenError, ScmFileStatus, SHA1Result
from facebook.eden.ttypes import ScmFileStatus, SHA1Result
from facebook.eden.ttypes import TimeSpec
from .lib import testcase
@ -108,38 +108,6 @@ class ThriftTest(testcase.EdenRepoTest):
self.assertIsNotNone(error)
self.assertEqual(error_message, error.message)
def test_glob(self) -> None:
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['a*/file']))
self.assertCountEqual(
['adir/file', 'bdir/file'],
self.client.glob(self.mount, ['**/file'])
)
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/*']))
self.assertCountEqual(
['adir/file', 'bdir/file'],
self.client.glob(self.mount, ['adir/*', '**/file']),
msg='De-duplicate results from multiple globs')
self.assertEqual(
['hello'], self.client.glob(self.mount, ['hello']))
self.assertEqual(
[], self.client.glob(self.mount, ['hell']),
msg="No accidental substring match")
self.assertEqual(
['hello'], self.client.glob(self.mount, ['hel*']))
self.assertEqual(
['adir'], self.client.glob(self.mount, ['ad*']))
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/**/*']))
self.assertEqual(
['adir/file'], self.client.glob(self.mount, ['adir/**']))
with self.assertRaises(EdenError) as ctx:
self.client.glob(self.mount, ['adir['])
self.assertIn('unterminated bracket sequence',
str(ctx.exception))
def test_unload_free_inodes(self) -> None:
for i in range(100):
self.write_file('testfile%d.txt' % i, 'unload test case')