def test_merge(self):
        uut = SectionManager()
        tmp = StringConstants.system_coafile
        StringConstants.system_coafile=os.path.abspath(os.path.join(
            os.path.dirname(inspect.getfile(SectionManagerTestCase)),
            "section_manager_test_files",
            "default_coafile"))

        config = os.path.abspath(os.path.join(
            os.path.dirname(inspect.getfile(SectionManagerTestCase)),
            "section_manager_test_files",
            ".coafile"))
        # Check merging of default_coafile and .coafile
        conf_sections = uut.run(arg_list=["-c", config])[0]
        self.assertEqual(str(conf_sections["test"]),
                         "test {value : 2}")
        self.assertEqual(str(conf_sections["test-2"]),
                         "test-2 {files : ., bears : LineCountBear}")
        # Check merging of default_coafile, .coafile and cli
        conf_sections = uut.run(arg_list=["-c",
                                          config,
                                          "-S",
                                          "test.value=3",
                                          "test-2.bears=",
                                          "test-5.bears=TestBear2"])[0]
        self.assertEqual(str(conf_sections["test"]), "test {value : 3}")
        self.assertEqual(str(conf_sections["test-2"]),
                         "test-2 {files : ., bears : }")
        self.assertEqual(str(conf_sections["test-3"]),
                         "test-3 {files : MakeFile}")
        self.assertEqual(str(conf_sections["test-4"]),
                         "test-4 {bears : TestBear}")
        self.assertEqual(str(conf_sections["test-5"]),
                         "test-5 {bears : TestBear2}")
        StringConstants.system_coafile = tmp
Exemple #2
0
 def test_merge_defaults(self):
     uut = SectionManager()
     conf_sections = uut.run(arg_list=[
         "-S", "value=1", "test.value=2", "-c", "some_bad_file_name"
     ])[0]
     self.assertEqual(conf_sections["default"],
                      conf_sections["test"].defaults)
Exemple #3
0
    def test_merge(self):
        uut = SectionManager()
        tmp = StringConstants.system_coafile
        StringConstants.system_coafile = os.path.abspath(
            os.path.join(
                os.path.dirname(inspect.getfile(SectionManagerTestCase)),
                "section_manager_test_files", "default_coafile"))

        config = os.path.abspath(
            os.path.join(
                os.path.dirname(inspect.getfile(SectionManagerTestCase)),
                "section_manager_test_files", ".coafile"))
        # Check merging of default_coafile and .coafile
        conf_sections = uut.run(arg_list=["-c", config])[0]
        self.assertEqual(str(conf_sections["test"]), "test {value : 2}")
        self.assertEqual(str(conf_sections["test-2"]),
                         "test-2 {files : ., bears : LineCountBear}")
        # Check merging of default_coafile, .coafile and cli
        conf_sections = uut.run(arg_list=[
            "-c", config, "-S", "test.value=3", "test-2.bears=",
            "test-5.bears=TestBear2"
        ])[0]
        self.assertEqual(str(conf_sections["test"]), "test {value : 3}")
        self.assertEqual(str(conf_sections["test-2"]),
                         "test-2 {files : ., bears : }")
        self.assertEqual(str(conf_sections["test-3"]),
                         "test-3 {files : MakeFile}")
        self.assertEqual(str(conf_sections["test-4"]),
                         "test-4 {bears : TestBear}")
        self.assertEqual(str(conf_sections["test-5"]),
                         "test-5 {bears : TestBear2}")
        StringConstants.system_coafile = tmp
Exemple #4
0
    def test_nonexistent_file(self):
        filename = "bad.one/test\neven with bad chars in it"
        SectionManager().run(arg_list=['-S', "config=" + filename
                                       ])  # Shouldn't throw an exception

        tmp = StringConstants.coalib_root
        StringConstants.coalib_root = filename
        self.assertRaises(SystemExit, SectionManager().run)
        StringConstants.coalib_root = tmp
 def test_merge_defaults(self):
     uut = SectionManager()
     conf_sections = uut.run(arg_list=["-S",
                                       "value=1",
                                       "test.value=2",
                                       "-c",
                                       "some_bad_file_name"])[0]
     self.assertEqual(conf_sections["default"],
                      conf_sections["test"].defaults)
Exemple #6
0
    def test_nonexistent_file():
        filename = "bad.one/test\neven with bad chars in it"
        # Shouldn't throw an exception
        SectionManager().run(arg_list=['-S', "config=" + filename])

        tmp = StringConstants.system_coafile
        StringConstants.system_coafile = filename
        # Shouldn't throw an exception
        SectionManager().run()
        StringConstants.system_coafile = tmp
 def test_user_coafile_parsing(self):
     uut = SectionManager()
     tmp = StringConstants.user_coafile
     StringConstants.user_coafile = os.path.abspath(os.path.join(
         os.path.dirname(inspect.getfile(SectionManagerTestCase)),
         "section_manager_test_files",
         "default_coafile"))
     uut.run()
     conf_sections = uut.default_sections
     self.assertEqual(str(conf_sections["test"]),
                      "test {value : 1, testval : 5}")
     StringConstants.user_coafile = tmp
Exemple #8
0
 def test_user_coafile_parsing(self):
     uut = SectionManager()
     tmp = StringConstants.user_coafile
     StringConstants.user_coafile = os.path.abspath(
         os.path.join(
             os.path.dirname(inspect.getfile(SectionManagerTestCase)),
             "section_manager_test_files", "default_coafile"))
     uut.run()
     conf_sections = uut.default_sections
     self.assertEqual(str(conf_sections["test"]),
                      "test {value : 1, testval : 5}")
     StringConstants.user_coafile = tmp
Exemple #9
0
    def test_run(self):
        uut = SectionManager()
        # We need to use a bad filename or this will parse coalas .coafile
        conf_sections = uut.run(
            arg_list=['-S', "test=5", "-c", "some_bad_filename"])[0]

        self.assertEqual(str(conf_sections["default"]),
                         "Default {config : some_bad_filename, test : 5}")

        local_bears = uut.run(
            arg_list=['-S test=5', '-c bad_filename', '-b LineCountBear'])[1]
        self.assertEqual(len(local_bears["default"]), 1)
    def test_run(self):
        uut = SectionManager()
        # We need to use a bad filename or this will parse coalas .coafile
        conf_sections = uut.run(
            arg_list=['-S', "test=5", "-c", "some_bad_filename"])[0]

        self.assertEqual(str(conf_sections["default"]),
                         "Default {config : some_bad_filename, test : 5}")

        local_bears = uut.run(arg_list=['-S test=5',
                                        '-c bad_filename',
                                        '-b LineCountBear'])[1]
        self.assertEqual(len(local_bears["default"]), 1)
Exemple #11
0
    def test_run(self):
        defaults = ConfParser().parse(
            os.path.abspath(
                os.path.join(StringConstants.coalib_root, "default_coafile")))

        uut = SectionManager()
        # We need to use a bad filename or this will parse the .coafile we use for coala
        conf_sections = uut.run(
            arg_list=['-S', "test=5", "-c", "some_bad_filename"])[0]

        self.assertEqual(str(conf_sections["default"]),
                         "Default {config : some_bad_filename, test : 5}")
        self.assertEqual(str(conf_sections["default"].defaults),
                         str(defaults["default"]))
Exemple #12
0
    def setUp(self):
        config_path = os.path.abspath(os.path.join(
            os.path.dirname(inspect.getfile(SectionExecutorTestCase)),
            "section_executor_test_files",
            ".coafile"))
        self.testcode_c_path = os.path.join(os.path.dirname(config_path),
                                            "testcode.c")

        self.sections, self.local_bears, self.global_bears, targets =\
            SectionManager().run(["--config", config_path])
        self.assertEqual(len(self.local_bears["default"]), 1)
        self.assertEqual(len(self.global_bears["default"]), 1)
        self.assertEqual(targets, [])

        self.result_queue = queue.Queue()
        self.log_queue = queue.Queue()

        self.interactor = SectionExecutorTestInteractor(self.result_queue,
                                                        self.log_queue)

        self.sections["default"].interactor = self.interactor
        self.sections["default"].log_printer = self.interactor
        self.uut = SectionExecutor(self.sections["default"],
                                   self.local_bears["default"],
                                   self.global_bears["default"])
Exemple #13
0
    def test_back_saving(self):
        filename = os.path.join(tempfile.gettempdir(),
                                "SectionManagerTestFile")

        # We need to use a bad filename or this will parse the .coafile we use for coala
        SectionManager().run(
            arg_list=['-S', "save=" + filename, "-c", "some_bad_filename"])

        with open(filename, "r") as f:
            lines = f.readlines()
        self.assertEqual(["[Default]\n", "config = some_bad_filename\n"],
                         lines)

        SectionManager().run(
            arg_list=['-S', "save=true", "config=" + filename, "test.value=5"])

        with open(filename, "r") as f:
            lines = f.readlines()
        os.remove(filename)
        self.assertEqual([
            "[Default]\n", "config = " + filename + "\n", "[test]\n",
            "value = 5\n"
        ], lines)
Exemple #14
0
 def test_logging_objects(self):
     conf_sections, n, m = SectionManager().run(
         arg_list=['-S', "log_type=none"])
     self.assertIsInstance(conf_sections["default"].log_printer,
                           NullPrinter)
Exemple #15
0
 def test_targets(self):
     targets = SectionManager().run(
         arg_list=["default", "test1", "test2"])[3]
     self.assertEqual(targets, ["default", "test1", "test2"])