Ejemplo n.º 1
0
 def test_single_plugin_with_make_target(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     target = 'test-target'
     s = ts.Shell(['-t', target, '-c', command])
     s.plugins.register(test_plugin_with_make_target)
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.known_plugins, [test_plugin_with_make_target])
Ejemplo n.º 2
0
 def test_all_arguments(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     target = 'test-target'
     s = ts.Shell(['-t', target, '-c', command])
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.command, command)
     self.assertEqual(s.mt.target, target)
Ejemplo n.º 3
0
 def test_missing_extra_argument(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     target = 'test-target'
     s = ts.Shell(['-t', target, '-c', command])
     s.parser.add_argument('-d', '--date', help="current date")
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.command, command)
     self.assertEqual(s.mt.target, target)
     self.assertIsNone(s.mt.date)
Ejemplo n.º 4
0
 def test_multiple_plugin_without_make_target(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     s = ts.Shell(['-t', '-c', command])
     s.plugins.register(test_plugin_before_1)
     s.plugins.register(test_plugin_with_make_target)
     s.plugins.register(test_plugin_before_2)
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.known_plugins,
                      [test_plugin_before_1, test_plugin_before_2])
Ejemplo n.º 5
0
 def test_multiple_after_plugin(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     target = 'test-target'
     s = ts.Shell(['-t', target, '-c', command])
     s.plugins.register(test_plugin_after_1)
     s.plugins.register(test_plugin_after_2)
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.known_plugins,
                      [test_plugin_after_2, test_plugin_after_1])
Ejemplo n.º 6
0
                'unique_nr': random.randint(0, 1000000),
                'has_make_level': mt.has_makelevel(),
                'started_at': datetime.datetime.now().isoformat(),
                'tag': 'BEGIN'
            }
            fd.write(u"{}\n".format(json.dumps(data)))
            fd.flush()

            exit_code = next_plugin_fn(mt)

            data.update({
                'tag': 'END',
                'finished_at': datetime.datetime.now().isoformat(),
                'exit_code': exit_code
            })
            fd.write(u"{}\n".format(json.dumps(data)))
            fd.flush()

    except IOError:
        exit_code = next_plugin_fn(mt)

    return exit_code


if __name__ == '__main__':
    shell = ts.Shell(sys.argv[1:])
    shell.parser.add_argument('-d', '--date', help="current date")
    shell.cls = MakeTarget
    shell.plugins.register(timing_env_plugin)
    shell.plugins.register(target_plugin)
    shell.delegate()
Ejemplo n.º 7
0
 def test_missing_command(self):
     s = ts.Shell(['-c'])
     with self.assertRaises(SystemExit):
         s.delegate()
Ejemplo n.º 8
0
 def test_echo_success(self):
     s = ts.Shell(['-c', 'echo "trackingshell" &>/dev/null'])
     exit_code = s.delegate(return_exit_code=True)
     self.assertEqual(exit_code, 0)
Ejemplo n.º 9
0
 def test_not_defined_target_argument(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     s = ts.Shell(['-c', command])
     s.delegate(return_exit_code=True)
     self.assertEqual(s.mt.command, command)
     self.assertEqual(s.mt.target, ts.MakeTarget.WITHOUT_TARGET)
Ejemplo n.º 10
0
 def test_subcommand_success(self):
     s = ts.Shell(['-c', 'echo $(date +%Y-%m-%d) &>/dev/null'])
     exit_code = s.delegate(return_exit_code=True)
     self.assertEqual(exit_code, 0)
Ejemplo n.º 11
0
 def test_multiple_echo_failed(self):
     s = ts.Shell(
         ['-c', 'echo tracking &>/dev/null && ecsho shell &>/dev/null'])
     exit_code = s.delegate(return_exit_code=True)
     self.assertEqual(exit_code, 127)
Ejemplo n.º 12
0
 def test_single_plugin_without_make_target(self):
     command = 'echo $(date +%Y-%m-%d) &>/dev/null'
     s = ts.Shell(['-t', '-c', command])
     s.plugins.register(test_plugin_with_make_target)
     s.delegate(return_exit_code=True)
     self.assertFalse(hasattr(s.mt, 'known_plugins'))