Example #1
0
def main(args=None):
    """The main routine."""

    if args is None:
        args = sys.argv[1:]

    parser = Main.getOptParser()
    options = parser.parse_args(args)

    mgr = Main(options)
    mgr.process()
Example #2
0
    def setUp(self):
        try:
            if self.__class__ in (BaseCommand, ):
                return

            super(BaseCommand, self).setUp()
            options = self.parser.parse_args(
                ["--init", "--workdir", self.testdir])

            self.mgr = Main(options)
            self.config = self.mgr.config["Command"]["tasks"][self.taskname]
        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #3
0
    def test_001_scan(self):
        try:

            with patch.object(Command,
                              "_subprocess",
                              side_effect=self.fake_subprocess) as mock_method:

                options = self.get_options()
                self.mgr = Main(options)
                self.mgr.process()

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #4
0
    def test_005_build(self):
        try:
            if not self.has_run():
                self.test_001_scan()

            options = self.parser.parse_args(
                ["--build", "--workdir", self.workdir])
            self.build_mgr = Main(options)
            if rpdb():
                pdb.set_trace()
            self.build_mgr.process()

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #5
0
 def test_002_badconfig(self):
     try:
         options = self.parser.parse_args(["--config", "notexist.yaml"])
         mgr = Main(options)
         self.fail("expected IOError")
     except (IOError, FileNotFoundError) as e:
         pass
     except (Exception, ) as e:
         if cpdb():
             pdb.set_trace()
         raise
Example #6
0
    def setUp(self):
        """Set up test fixtures, if any."""

        self.testdir_base = (getattr(self, "testdir_base", None)
                             or self.set_testdirbase())

        self.oldpwd = os.getcwd()

        if self.testdir:
            os.chdir(self.testdir)
        self.parser = Main.getOptParser()
        self.stderr = ""
Example #7
0
    def test_001_noconfig(self):
        try:
            options = self.parser.parse_args([])
            mgr = Main(options)
            self.fail("should have complained about missing configuration")

        except (SystemExit, ) as e:
            pass

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #8
0
class BaseCommand(WriterMixin, Base):
    def setUp(self):
        try:
            if self.__class__ in (BaseCommand, ):
                return

            super(BaseCommand, self).setUp()
            options = self.parser.parse_args(
                ["--init", "--workdir", self.testdir])

            self.mgr = Main(options)
            self.config = self.mgr.config["Command"]["tasks"][self.taskname]
        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    def test_run(self):
        if self.__class__ in (BaseCommand, ):
            return

        try:
            command = Command(self.mgr, self.taskname, self.config)
            command.run()
            from time import sleep

            sleep(0.5)
            fnp = self.mgr._get_fnp(self.taskname)
            with open(fnp) as fi:
                data = fi.read()
                self.assertTrue(data, "%s was empty" % (fnp))

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #9
0
class BasePip_Scan(WriterMixin, Base):
    pass

    fake_subprocess_payload = dict(freeze="""PyQt5==5.12
PyQt5-sip==4.19.14
pyquery==1.4.0
pytest==4.4.0
python-dateutil==2.8.0
python-editor==1.0.4
""")

    # this is used to run scan only once
    fn_marker = FN_SCAN

    def setUp(self):
        super(BasePip_Scan, self).setUp()
        self.workdir = self.seed()

    def get_options(self):
        return self.parser.parse_args(["--init", "--workdir", self.workdir])

    def fake_subprocess(self, cmd, fnp_o, self_):
        try:
            if self_.taskname != "freeze":
                return self_._subprocess_actual(cmd, fnp_o, self_)

            with open(fnp_o, self_.mode) as fo:
                fo.write(self.fake_subprocess_payload["freeze"])

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    def test_001_scan(self):
        try:

            with patch.object(Command,
                              "_subprocess",
                              side_effect=self.fake_subprocess) as mock_method:

                options = self.get_options()
                self.mgr = Main(options)
                self.mgr.process()

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    exp_imports = []

    def test_002_greps(self):
        try:
            if not self.has_run():
                self.test_001_scan()

            with self.get_file(FN_IMPORTS_GREP) as fi:
                data = fi.read()

            for import_ in self.exp_imports:
                self.assertTrue(
                    import_ in data,
                    "missing %s from %s" % (import_, FN_IMPORTS_GREP))

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    exp_tests_requirements = []

    def test_0031_import_tracker(self):
        try:
            if not self.exp_tests_requirements:
                return

            if not self.has_run():
                self.test_001_scan()

            exp = "tests"

            for req in self.exp_tests_requirements:
                got = self.mgr.import_classifier.packagetracker.di_packagename[
                    req]
                self.assertEqual(exp, got,
                                 "%s:exp:%s<>%s:got" % (req, exp, got))
        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    def test_0032_test_bucket(self):
        try:

            if not self.exp_tests_requirements:
                return

            if not self.has_run():
                self.test_001_scan()

            with self.get_file(FN_SCAN) as fi:
                data = yload(fi)

            got_all = data["pips"]["buckets"]["tests"]
            t_msg = "missing %s from %s.%s"

            for exp in self.exp_tests_requirements:

                found = self.mgr.import_classifier.packagetracker.di_packagename[
                    exp]

                msg = t_msg % (exp, FN_SCAN, ":pips/tests/")
                self.assertTrue(exp in got_all, msg)
        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise

    def test_005_build(self):
        try:
            if not self.has_run():
                self.test_001_scan()

            options = self.parser.parse_args(
                ["--build", "--workdir", self.workdir])
            self.build_mgr = Main(options)
            if rpdb():
                pdb.set_trace()
            self.build_mgr.process()

        except (Exception, ) as e:
            if cpdb():
                pdb.set_trace()
            raise
Example #10
0
 def setUp(self):
     super(TestPip_Init, self).setUp()
     self.options = self.get_options()
     self.mgr = Main(self.options)