Example #1
0
 def test_new_default_driver(self):
     with TemporaryDirectory(cd=True) as d:
         sys.argv = ['subdue', 'new', 'mysub']
         with OutStreamCheckedCapture(self):
             subdue.main()
         driver = os.path.join(d, 'mysub', 'bin', 'mysub')
         self.assertOsPathIsFile(driver)
         self.assertIsExecutable(driver)
         with open(driver) as f:
             driver_text = f.read()
         self.assertEqual(driver_text, subdue.core.DEFAULT_DRIVER_CODE)
Example #2
0
 def test_new_default_driver(self):
     with TemporaryDirectory(cd=True) as d:
         sys.argv = ['subdue', 'new', 'mysub']
         with OutStreamCheckedCapture(self):
             subdue.main()
         driver = os.path.join(d, 'mysub', 'bin', 'mysub')
         self.assertOsPathIsFile(driver)
         self.assertIsExecutable(driver)
         with open(driver) as f:
             driver_text = f.read()
         self.assertEqual(driver_text, subdue.core.DEFAULT_DRIVER_CODE)
Example #3
0
 def test_new_thin(self):
     with TemporaryDirectory(cd=True) as d:
         sys.argv = ['subdue', 'new', '--thin', 'mysub']
         with OutStreamCheckedCapture(self) as cap:
             subdue.main()
         cap.stdout.contains(subdue.core.BANNER)
         subroot = os.path.join(d, 'mysub')
         self.assertOsPathIsDir(subroot)
         self.assertNotOsPathExists(os.path.join(subroot, 'bin'))
         self.assertOsPathIsDir(os.path.join(subroot, 'commands'))
         self.assertOsPathIsDir(os.path.join(subroot, 'share'))
         self.assertOsPathIsDir(os.path.join(subroot, 'lib'))
Example #4
0
 def test_new_fat(self):
     with TemporaryDirectory(cd=True) as d:
         sys.argv = ['subdue', 'new', 'mysub']
         with OutStreamCheckedCapture(self) as cap:
             subdue.main()
         cap.stdout.contains(subdue.core.BANNER)
         subroot = os.path.join(d, 'mysub')
         self.assertOsPathIsDir(subroot)
         self.assertOsPathIsDir(os.path.join(subroot, 'bin'))
         self.assertOsPathIsDir(os.path.join(subroot, 'commands'))
         self.assertOsPathIsDir(os.path.join(subroot, 'share'))
         self.assertOsPathIsDir(os.path.join(subroot, 'lib'))
Example #5
0
    def test_is_eval(self):
        subname = 'evalsub'
        with TemporaryDirectory(cd=True) as d:

            with OutStreamCheckedCapture(self):
                subdue.main(['subdue', 'new', subname])

            sub_root = os.path.join(d, subname)
            utils.create_subcommand(sub_root, 'sh-eval', """\
                #!/bin/bash
                echo "This is my eval command"
                """)
            utils.create_subcommand(sub_root, 'foobar', """\
                #!/bin/bash
                echo "This is my regular command"
                """)

            self.assertIsEval(sub_root, 'eval')
            self.assertIsNotEval(sub_root, 'sh-eval')
            self.assertIsNotEval(sub_root, 'foobar')
Example #6
0
    def test_top_level_launch_fat(self):
        """
        Launch a top level subcommand with the driver
        """
        with TemporaryDirectory(cd=True) as d:

            with OutStreamCheckedCapture(self):
                subdue.main(['subdue', 'new', 'mysub'])

            sub_root = os.path.join(d, 'mysub')
            utils.create_subcommand(sub_root, 'mycommand', """\
                #!/bin/bash
                echo "This is foo"
                """)

            with OutStreamCheckedCapture(self) as cap:
                return_code = utils.call_driver_for(sub_root, ['mycommand'])

            self.assertEqual(return_code, 0, "Return code ({}) != expected ({}). Capture: {}".format(return_code, 0, cap))
            cap.stdout.matches(r"^This is foo\n")
Example #7
0
    def test_top_level_launch_thin(self):
        """
        Launch a top level subcommand with the library
        """
        with TemporaryDirectory(cd=True) as d:
            with OutStreamCheckedCapture(self):
                subdue.main(['subdue', 'new', '--thin', 'mysub'])

            sub_root = os.path.join(d, 'mysub')
            utils.create_subcommand(sub_root, 'mycommand', """\
                #!/bin/bash
                echo "This is foo"
                """)

            caller = utils.SubprocessCaller()
            with OutStreamCheckedCapture(self) as cap:
                subdue.sub.main(['mycommand'],
                                sub_path=sub_root,
                                command_runner=caller,
                                exit=False)
            self.assertIsNotNone(caller.returncode, "No command was called. {}".format(cap))
            self.assertEqual(caller.returncode, 0)
            cap.stdout.matches(r"^This is foo\n")
Example #8
0
File: utils.py Project: bazl/subdue
 def __enter__(self):
     super(TempSub, self).__enter__()
     with OutStreamCapture():
         subdue.main(['subdue', 'new', self.subname])
     return TempSub.Sub(self)
Example #9
0
 def new_bad(name):
     with OutStreamCheckedCapture(self) as cap:
         with self.assertRaises(SystemExit):
             subdue.main(['subdue', 'new', '--', name])
     return cap.stderr
Example #10
0
 def new_bad(name):
     with OutStreamCheckedCapture(self) as cap:
         with self.assertRaises(SystemExit):
             subdue.main(['subdue', 'new', '--', name])
     return cap.stderr
Example #11
0
 def __enter__(self):
     super(TempSub, self).__enter__()
     with OutStreamCapture():
         subdue.main(['subdue', 'new', self.subname])
     return TempSub.Sub(self)