예제 #1
0
파일: test.py 프로젝트: jdevera/subdue
 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)
예제 #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)
예제 #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'))
예제 #4
0
파일: test.py 프로젝트: jdevera/subdue
 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'))
예제 #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')
예제 #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")
예제 #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")
예제 #8
0
파일: utils.py 프로젝트: bazl/subdue
 def __enter__(self):
     super(TempSub, self).__enter__()
     with OutStreamCapture():
         subdue.main(['subdue', 'new', self.subname])
     return TempSub.Sub(self)
예제 #9
0
 def new_bad(name):
     with OutStreamCheckedCapture(self) as cap:
         with self.assertRaises(SystemExit):
             subdue.main(['subdue', 'new', '--', name])
     return cap.stderr
예제 #10
0
파일: test.py 프로젝트: jdevera/subdue
 def new_bad(name):
     with OutStreamCheckedCapture(self) as cap:
         with self.assertRaises(SystemExit):
             subdue.main(['subdue', 'new', '--', name])
     return cap.stderr
예제 #11
0
파일: utils.py 프로젝트: jdevera/subdue
 def __enter__(self):
     super(TempSub, self).__enter__()
     with OutStreamCapture():
         subdue.main(['subdue', 'new', self.subname])
     return TempSub.Sub(self)