Ejemplo n.º 1
0
    def test_check_perl_import(self):
        """Check to make sure check_perl_import works"""
        env = DummyEnv({'service_module': 'testmodule',
                        'perldir': '/my/test/perldir'})
        ret, warns = run_catch_warnings(saliweb.build._check_perl_import, env)
        self.assertEqual(len(warns), 1)
        self.assert_(re.search('Perl module.*\/my\/test\/perldir\/testmodule'
                               '\.pm does not.*frontend will probably not '
                               'work.*Perl module is named \'testmodule\'.*'
                               'InstallPerl.*SConscript',
                               warns[0][0].args[0], re.DOTALL),
                     'regex did not match ' + warns[0][0].args[0])

        env = DummyEnv({'service_module': 'testmodule',
                        'perldir': '/my/test/okperldir'})
        ret, warns = run_catch_warnings(saliweb.build._check_perl_import, env)
        self.assertEqual(len(warns), 0)
Ejemplo n.º 2
0
    def test_check_perl_import(self):
        """Check to make sure check_perl_import works"""
        env = DummyEnv({'service_module': 'testmodule',
                        'perldir': '/my/test/perldir'})
        ret, warns = run_catch_warnings(saliweb.build._check_perl_import, env)
        self.assertEqual(len(warns), 1)
        self.assert_(re.search('Perl module.*\/my\/test\/perldir\/testmodule'
                               '\.pm does not.*frontend will probably not '
                               'work.*Perl module is named \'testmodule\'.*'
                               'InstallPerl.*SConscript',
                               warns[0][0].args[0], re.DOTALL),
                     'regex did not match ' + warns[0][0].args[0])

        env = DummyEnv({'service_module': 'testmodule',
                        'perldir': '/my/test/okperldir'})
        ret, warns = run_catch_warnings(saliweb.build._check_perl_import, env)
        self.assertEqual(len(warns), 0)
Ejemplo n.º 3
0
    def test_check_python_import(self):
        """Check to make sure check_python_import works"""
        env = DummyEnv({'service_module': 'testmodule',
                        'pythondir': '/my/test/pythondir'})
        ret, warns = run_catch_warnings(saliweb.build._check_python_import, env)
        self.assertEqual(len(warns), 1)
        self.assert_(re.search('Python module.*\/my\/test\/pythondir\/'
                               'testmodule\/__init__\.py does not.*backend '
                               'will probably not work.*Python package is '
                               'named \'testmodule\'.*'
                               'InstallPython.*SConscript',
                               warns[0][0].args[0], re.DOTALL),
                     'regex did not match ' + warns[0][0].args[0])

        env = DummyEnv({'service_module': 'testmodule',
                        'pythondir': '/my/test/okpythondir'})
        ret, warns = run_catch_warnings(saliweb.build._check_python_import, env)
        self.assertEqual(len(warns), 0)
Ejemplo n.º 4
0
    def test_check_python_import(self):
        """Check to make sure check_python_import works"""
        env = DummyEnv({'service_module': 'testmodule',
                        'pythondir': '/my/test/pythondir'})
        ret, warns = run_catch_warnings(saliweb.build._check_python_import, env)
        self.assertEqual(len(warns), 1)
        self.assert_(re.search('Python module.*\/my\/test\/pythondir\/'
                               'testmodule\/__init__\.py does not.*backend '
                               'will probably not work.*Python package is '
                               'named \'testmodule\'.*'
                               'InstallPython.*SConscript',
                               warns[0][0].args[0], re.DOTALL),
                     'regex did not match ' + warns[0][0].args[0])

        env = DummyEnv({'service_module': 'testmodule',
                        'pythondir': '/my/test/okpythondir'})
        ret, warns = run_catch_warnings(saliweb.build._check_python_import, env)
        self.assertEqual(len(warns), 0)
Ejemplo n.º 5
0
    def test_setup_version(self):
        """Check _setup_version function"""
        class BrokenEnv(dict):
            def __init__(self, bin):
                dict.__init__(self)
                self.bin = bin
            def WhereIs(self, bin): return self.bin
        tmpdir = tempfile.mkdtemp()
        def get_broken_env_pyscript(name, script):
            tmpfile = os.path.join(tmpdir, name)
            print >> open(tmpfile, 'w'), "#!/usr/bin/python\n" + script
            os.chmod(tmpfile, 0755)
            return BrokenEnv(tmpfile)
        curdir = RunInTempDir()

        # Check with provided version number
        env = {}
        saliweb.build._setup_version(env, '1.0')
        self.assertEqual(env, {'version': '1.0'})

        # No number provided; no svnversion binary in path
        env = BrokenEnv(None)
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 1)
        self.assertEqual(warns[0][0].args,
                         ("Could not find 'svnversion' binary in path",))
        self.assertEqual(env, {'version': None})

        # No number provided; cannot find svnversion binary
        env = BrokenEnv('/not/exist/svnversion')
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 1)
        self.assertEqual(warns[0][0].args,
                         ("Could not run /not/exist/svnversion: [Errno 2] "
                          "No such file or directory",))
        self.assertEqual(env, {'version': None})

        # No number provided; svnversion binary reports 'exported'
        env = get_broken_env_pyscript('expscript', 'print "exported"')
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 0)
        self.assertEqual(env, {'version': None})

        # No number provided; svnversion binary returns error
        env = get_broken_env_pyscript('errscript', """
import sys
print >> sys.stderr, "error text"
print "output text"
sys.exit(1)""")
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 1)
        self.assert_(re.match('Could not run \S+\/errscript: returned exit '
                              'code 1, stdout output text\n, '
                              'stderr error text\n$', warns[0][0].args[0]),
                     "%s does not match re" % warns[0][0].args[0])
        self.assertEqual(env, {'version': None})

        # No number provided; svnversion binary works
        env = get_broken_env_pyscript('workscript', 'print "1024\\n2048"')
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 0)
        self.assertEqual(env, {'version': 'r1024'}) # Only first line used

        # git repository
        os.mkdir('.git')
        env = get_broken_env_pyscript('gitscript', """
import sys
if sys.argv[1:4] == ['rev-parse', '--abbrev-ref', 'HEAD']:
    print "master\\nfoo"
elif sys.argv[1:4] == ['rev-parse', '--short', 'HEAD']:
    print "abc123\\nbar"
else:
    raise IOError(sys.argv)
""")
        ret, warns = run_catch_warnings(saliweb.build._setup_version, env, None)
        self.assertEqual(len(warns), 0)
        self.assertEqual(env, {'version': 'master.abc123'})

        shutil.rmtree(tmpdir, ignore_errors=True)
Ejemplo n.º 6
0
    def test_setup_version(self):
        """Check _setup_version function"""
        class BrokenEnv(dict):
            def __init__(self, bin):
                dict.__init__(self)
                self.bin = bin

            def WhereIs(self, bin):
                return self.bin

        tmpdir = tempfile.mkdtemp()

        def get_broken_env_pyscript(name, script):
            tmpfile = os.path.join(tmpdir, name)
            with open(tmpfile, 'w') as fh:
                print("#!/usr/bin/python\n" + script, file=fh)
            os.chmod(tmpfile, 0755)
            return BrokenEnv(tmpfile)

        with testutil.temp_working_dir():
            # Check with provided version number
            env = {}
            saliweb.build._setup_version(env, '1.0')
            self.assertEqual(env, {'version': '1.0'})

            # No number provided; no svnversion binary in path
            env = BrokenEnv(None)
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 1)
            self.assertEqual(warns[0][0].args,
                             ("Could not find 'svnversion' binary in path", ))
            self.assertEqual(env, {'version': None})

            # No number provided; cannot find svnversion binary
            env = BrokenEnv('/not/exist/svnversion')
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 1)
            self.assertEqual(warns[0][0].args,
                             ("Could not run /not/exist/svnversion: [Errno 2] "
                              "No such file or directory", ))
            self.assertEqual(env, {'version': None})

            # No number provided; svnversion binary reports 'exported'
            env = get_broken_env_pyscript(
                'expscript', """
from __future__ import print_function
print("exported")""")
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 0)
            self.assertEqual(env, {'version': None})

            # No number provided; svnversion binary returns error
            env = get_broken_env_pyscript(
                'errscript', """
from __future__ import print_function
import sys
print("error text", file=sys.stderr)
print("output text")
sys.exit(1)""")
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 1)
            self.assert_(
                re.match(
                    'Could not run \S+\/errscript: returned exit '
                    'code 1, stdout output text\n, '
                    'stderr error text\n$', warns[0][0].args[0]),
                "%s does not match re" % warns[0][0].args[0])
            self.assertEqual(env, {'version': None})

            # No number provided; svnversion binary works
            env = get_broken_env_pyscript(
                'workscript', """
from __future__ import print_function
print("1024\\n2048")""")
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 0)
            self.assertEqual(env, {'version': 'r1024'})  # Only first line used

            # git repository
            os.mkdir('.git')
            env = get_broken_env_pyscript(
                'gitscript', """
from __future__ import print_function
import sys
if sys.argv[1:4] == ['rev-parse', '--abbrev-ref', 'HEAD']:
    print("master\\nfoo")
elif sys.argv[1:4] == ['rev-parse', '--short', 'HEAD']:
    print("abc123\\nbar")
else:
    raise IOError(sys.argv)
""")
            ret, warns = run_catch_warnings(saliweb.build._setup_version, env,
                                            None)
            self.assertEqual(len(warns), 0)
            self.assertEqual(env, {'version': 'master.abc123'})

            shutil.rmtree(tmpdir, ignore_errors=True)