def test_strips_leading_and_trailing_parentheticals(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() self.assertEqual(f('(foo) bar (baz)'), 'bar') self.assertEqual(f('(foo bar) baz (qux)'), 'baz') self.assertEqual(f('(foo) bar (baz qux)'), 'bar') self.assertEqual(f('(foo bar) baz (qux quux)'), 'baz')
def test_strips_trailing_parenthetical(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() # with whitespace self.assertEqual(f('foo (bar)'), 'foo') self.assertEqual(f('foo (bar baz)'), 'foo') # without whitespace self.assertEqual(f('foo(bar)'), 'foo') self.assertEqual(f('foo(bar baz)'), 'foo')
def test_strips_leading_parenthetical(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() # with whitespace self.assertEqual(f('(foo) bar'), 'bar') self.assertEqual(f('(foo bar) baz'), 'baz') # without whitespace self.assertEqual(f('(foo)bar'), 'bar') self.assertEqual(f('(foo bar)baz'), 'baz')
def test_leaves_internal_parentheticals_alone(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() # with whitespace self.assertEqual(f('foo (bar) baz'), 'foo (bar) baz') # without whitespace self.assertEqual(f('foo (bar)baz'), 'foo (bar)baz') self.assertEqual(f('foo(bar) baz'), 'foo(bar) baz') self.assertEqual(f('foo(bar)baz'), 'foo(bar)baz')
def test_strips_repeated_parentheticals(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() # leading self.assertEqual(f('(foo) (bar) baz'), 'baz') self.assertEqual(f('(foo bar) (baz) qux'), 'qux') # trailing self.assertEqual(f('foo (bar) (baz)'), 'foo') self.assertEqual(f('foo (bar baz) (qux)'), 'foo') # leading and trailing self.assertEqual(f('(foo) (bar) baz (qux) (quux)'), 'baz')
def test_when_strip_trailing_is_false(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer( strip_trailing=False) # test that it does strip leading self.assertEqual(f('(foo) bar'), 'bar') self.assertEqual(f('(foo bar) baz'), 'baz') self.assertEqual(f('(foo)bar'), 'bar') self.assertEqual(f('(foo bar)baz'), 'baz') # test that it does not strip trailing self.assertEqual(f('foo (bar)'), 'foo (bar)') self.assertEqual(f('foo (bar baz)'), 'foo (bar baz)') self.assertEqual(f('foo(bar)'), 'foo(bar)') self.assertEqual(f('foo(bar baz)'), 'foo(bar baz)')
def test_leaves_normal_text_alone(self): f = normalizers.StripLeadingAndTrailingParentheticalsNormalizer() self.assertEqual(f('foo'), 'foo') self.assertEqual(f('foo bar'), 'foo bar')