Exemplo n.º 1
0
 def test_deploy_differing_outpaths_raises(self):
     '''If deploying rules with differing outpaths, raise an error.'''
     cat = Cat(FakeTemplater(
         self.tmpdir, {}))
     cat.rules = [
         Rule(self.srcfile1, self.outfile),
         Rule(self.srcfile2, self.tmpdir/'dne', force_rewrite=True)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.outfile.write_text('theme: cooltheme\nforeground: white')
     with self.assertRaises(ImproperOutpathError):
         cat.deploy()
Exemplo n.º 2
0
 def test_deploy_permissions_readonly(self):
     '''The output file should have readonly permissions.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     cat.rules = [Rule(self.srcfile1, self.outfile)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.outfile.write_text('theme: cooltheme\nforeground: white')
     self.outfile.chmod(0o000)
     cat.deploy()
     self.assertEqual(0o100444, self.outfile.stat().st_mode)
Exemplo n.º 3
0
 def test_deploy_equal_files_no_write(self):
     '''A cat that would not change the outfile shouldn't open it.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     outpathspy = Mock(wraps=self.outfile)
     cat.rules = [Rule(self.srcfile1, outpathspy)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.outfile.write_text('theme: cooltheme\nforeground: white')
     cat.deploy()
     # This is implementation-dependent -- look for a better option
     outpathspy.write_text.assert_not_called()
Exemplo n.º 4
0
 def test_deploy_file_dne_raises(self):
     '''A cat should raise an error if a src file dne.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     cat.rules = [
         Rule(self.srcfile1, self.outfile),
         Rule(self.tmpdir/'dne', self.outfile)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.outfile.write_text('some old garbage')
     with self.assertRaises(FileNotFoundError):
         cat.deploy()
Exemplo n.º 5
0
 def test_deploy_permissions_executable(self):
     '''The exec flag should cause the output file to be executable.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     cat.rules = [
         Rule(self.srcfile1, self.outfile),
         Rule(self.srcfile2, self.outfile, executable=True)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.srcfile2.write_text('')
     self.outfile.write_text('theme: cooltheme\nforeground: white')
     self.outfile.chmod(0o000)
     cat.deploy()
     self.assertEqual(0o100544, self.outfile.stat().st_mode)
Exemplo n.º 6
0
 def test_deploy_equal_files_flag_force_write(self):
     '''force_rewrite flag with equal output still writes the outfile.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     outpathspy = Mock(wraps=self.outfile)
     cat.rules = [
         Rule(self.srcfile1, outpathspy),
         Rule(self.srcfile2, outpathspy, force_rewrite=True)]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.outfile.write_text('theme: cooltheme\nforeground: white')
     cat.deploy()
     # This is implementation-dependent -- look for a better option
     outpathspy.write_text.assert_called()
Exemplo n.º 7
0
 def test_deploy_outfile_dne_write(self):
     '''A cat that would change the content of the file should write it.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     cat.rules = [
         Rule(self.srcfile1, self.tmpdir/'newoutfile'),
         Rule(self.srcfile2, self.tmpdir/'newoutfile')]
     self.srcfile1.write_text('theme: {{theme}}\nforeground: {{colorfg}}')
     self.srcfile2.write_text('background: {{ colorbg }}')
     cat.deploy()
     self.assertEqual(
         (self.tmpdir/'newoutfile').read_text(),
         'theme: cooltheme\nforeground: white\nbackground: blue')
Exemplo n.º 8
0
 def test_deploy_file_empty_ignored(self):
     '''A cat should not add anything to the outfile for an empty src.'''
     cat = Cat(FakeTemplater(
         self.tmpdir,
         {'theme': 'cooltheme', 'colorfg': 'white', 'colorbg': 'blue'}))
     cat.rules = [
         Rule(self.srcfile1, self.outfile),
         Rule(self.srcfile2, self.outfile)]
     self.srcfile1.write_text('something cool\nnewline')
     self.srcfile2.write_text('')
     self.outfile.write_text('some old garbage')
     cat.deploy()
     self.assertEqual(
         self.outfile.read_text(),
         'something cool\nnewline')