def test_auto_indent_adaptive(self): self.assertEquals(dedent(''' jar_library(name='hello', jars=[ jar(org='com.squareup', name='foobar', rev='1.0'), jar(org='com.squareup', name='barfoo', rev='0.1'), ], ) '''), GenerationUtils.autoindent(self._auto_indent_sample, adaptive=True, indent_size=2))
def test_auto_indent_sneaky_strings(self): expected = dedent(''' target( "stuff(" "more stuff": [ "Even more ] stuff", "Testing strings with \\"] sneaky escapes" ] ) ''').strip() received = GenerationUtils.autoindent(expected) self.assertEquals(expected, received, msg='Expected:\n{}\n\nReceived:\n{}\n'.format(expected, received))
def test_auto_indent_sneaky_strings(self): expected = dedent(''' target( "stuff(" "more stuff": [ "Even more ] stuff", "Testing strings with \\"] sneaky escapes" ] ) ''').strip() received = GenerationUtils.autoindent(expected) self.assertEquals(expected, received, msg='Expected:\n{}\n\nReceived:\n{}\n'.format( expected, received))
def test_auto_indent_adaptive(self): self.assertEquals( dedent(''' jar_library(name='hello', jars=[ jar(org='com.squareup', name='foobar', rev='1.0'), jar(org='com.squareup', name='barfoo', rev='0.1'), ], ) '''), GenerationUtils.autoindent(self._auto_indent_sample, adaptive=True, indent_size=2))
def test_resolve_properties(self): substitute = GenerationUtils.symbol_substitution with temporary_dir() as tmpdir: with open(os.path.join(tmpdir, 'pom.xml'), 'w') as root_pom_file: root_pom_file.write(self.ROOT_POM) pom_file = PomFile('pom.xml', root_directory=tmpdir) self.assertEquals('FOOBAR', substitute(pom_file.properties, '${prop.foo}${prop.bar}')) self.assertEquals('FOO-BAZ', substitute(pom_file.properties, '${prop.baz}')) deps = [{'key1' : 'key1-${prop.foo}'}, {'key2' : 'key2-${prop.bar}'}] deps = GenerationUtils.symbol_substitution_on_dicts(pom_file.properties, deps) self.assertEquals([{'key1' : 'key1-FOO'}, {'key2' : 'key2-BAR'}], deps)
def test_auto_indent_forced_linebreaks(self): self.assertEquals(dedent(''' jar_library( name='hello', jars=[ jar( org='com.squareup', name='foobar', rev='1.0'), jar( org='com.squareup', name='barfoo', rev='0.1'), ], ) '''), GenerationUtils.autoindent(self._auto_indent_sample, adaptive=False, indent_size=2, force_linebreaks_after='([{,'))
def test_resolve_properties(self): substitute = GenerationUtils.symbol_substitution with temporary_dir() as tmpdir: with open(os.path.join(tmpdir, 'pom.xml'), 'w') as root_pom_file: root_pom_file.write(self.ROOT_POM) pom_file = PomFile('pom.xml', root_directory=tmpdir) self.assertEquals( 'FOOBAR', substitute(pom_file.properties, '${prop.foo}${prop.bar}')) self.assertEquals('FOO-BAZ', substitute(pom_file.properties, '${prop.baz}')) deps = [{'key1': 'key1-${prop.foo}'}, {'key2': 'key2-${prop.bar}'}] deps = GenerationUtils.symbol_substitution_on_dicts( pom_file.properties, deps) self.assertEquals([{ 'key1': 'key1-FOO' }, { 'key2': 'key2-BAR' }], deps)
def test_auto_indent_preserve_block_indent(self): raw_block = '\n'.join([ ' target(', ' dependencies=[', ' ":one", ":two",', ' ":three"', ' ]', ' )', ]) expected_block = '\n'.join([ ' target(', ' dependencies=[', ' ":one", ":two",', ' ":three"', ' ]', ' )', ]) received = GenerationUtils.autoindent(raw_block) self.assertEquals(expected_block, received, msg='Expected:\n{}\n\nReceived:\n{}\n'.format(expected_block, received))
def test_auto_indent_forced_linebreaks(self): self.assertEquals( dedent(''' jar_library( name='hello', jars=[ jar( org='com.squareup', name='foobar', rev='1.0'), jar( org='com.squareup', name='barfoo', rev='0.1'), ], ) '''), GenerationUtils.autoindent(self._auto_indent_sample, adaptive=False, indent_size=2, force_linebreaks_after='([{,'))
def test_auto_indent_preserve_block_indent(self): raw_block = '\n'.join([ ' target(', ' dependencies=[', ' ":one", ":two",', ' ":three"', ' ]', ' )', ]) expected_block = '\n'.join([ ' target(', ' dependencies=[', ' ":one", ":two",', ' ":three"', ' ]', ' )', ]) received = GenerationUtils.autoindent(raw_block) self.assertEquals(expected_block, received, msg='Expected:\n{}\n\nReceived:\n{}\n'.format( expected_block, received))