def setUp(self):
        self.cs_language_without_config = CSLanguage()
        self.test_file_name = "cs_basic"
        self.test_src_name = self.test_file_name + ".cs"
        self.test_exe_name = self.test_file_name + ".exe"

        self.test_src_file_path = os.path.join(self.src_code_dir,
                                               self.test_src_name)
        self.test_exe_file_path = os.path.join(self.build_dir_bin,
                                               self.test_exe_name)
    def setUp(self):
        self.cs_language_without_config = CSLanguage()
        self.test_file_name = "cs_basic"
        self.test_src_name = self.test_file_name + ".cs"
        self.test_exe_name = self.test_file_name + ".exe"

        self.test_src_file_path = os.path.join(self.src_code_dir, self.test_src_name)
        self.test_exe_file_path = os.path.join(self.build_dir_bin, self.test_exe_name)
    def _build_algorithm(self, algorithm):
        if algorithm.language == CPPLanguage.get_name():
            language = CPPLanguage(self.config_parser)
        elif algorithm.language == CSLanguage.get_name():
            language = CSLanguage(self.config_parser)
        elif algorithm.language == FPLanguage.get_name():
            language = FPLanguage(self.config_parser)
        else:
            return [STATUS_ERROR_LANGUAGE_NOT_FOUND, "", ""]

        self.build_bot.set_language(language)

        algorithm_dir = self._get_algorithm_dir(algorithm)
        if not os.path.exists(algorithm_dir):
            os.makedirs(algorithm_dir)

        source_file = algorithm_dir + os.sep + algorithm.name + "." + language.get_extension()

        with open(source_file, "wb") as src_file:
            src_file.write(algorithm.source_code)

        exe_path = self._get_exe_path(algorithm)

        return self.build_bot.build(source_file, str(exe_path))
    def setUp(self):
        self.test_file_name = "cs_basic"
        self.test_src_name = self.test_file_name + ".cs"
        self.test_exe_name = self.test_file_name + ".exe"

        self.test_src_file_path = os.path.join(self.src_code_dir,
                                               self.test_src_name)

        self.output_dir = os.path.join(self.build_dir, "cfg_output_dir")
        if not os.path.exists(self.output_dir):
            os.makedirs(self.output_dir)
        self.test_exe_path = os.path.join(self.output_dir, self.test_exe_name)

        self.language = CSLanguage(self.config_parser)
        self.build_bot = BuildBot()
        self.build_bot.set_language(self.language)
    def _build_algorithm(self, algorithm):
        if algorithm.language == CPPLanguage.get_name():
            language = CPPLanguage(self.config_parser)
        elif algorithm.language == CSLanguage.get_name():
            language = CSLanguage(self.config_parser)
        elif algorithm.language == FPLanguage.get_name():
            language = FPLanguage(self.config_parser)
        else:
            return [STATUS_ERROR_LANGUAGE_NOT_FOUND, "", ""]

        self.build_bot.set_language(language)

        algorithm_dir = self._get_algorithm_dir(algorithm)
        if not os.path.exists(algorithm_dir):
            os.makedirs(algorithm_dir)

        source_file = algorithm_dir + os.sep + algorithm.name + "." + language.get_extension()

        with open(source_file, "wb") as src_file:
            src_file.write(algorithm.source_code)

        exe_path = self._get_exe_path(algorithm)

        return self.build_bot.build(source_file, str(exe_path))
 def test_can_successfully_compile_and_run_test_file_with_config(self):
     cs_language_with_config = CSLanguage(self.config_parser)
     self._compile(cs_language_with_config)
     (ret_code, out, err) = shell(self.test_exe_file_path)
     self.assertEquals(ret_code, 0)
     self.assertEquals(split_lines(out).pop(0), "Hello World using C#!")
 def test_can_successfully_call_csc_to_compile_test_file(self):
     cs_language_with_config = CSLanguage(self.config_parser)
     (ret_code, out, err) = self._compile(cs_language_with_config)
     self.assertEquals(ret_code, 0)
     self.assertTrue(os.path.exists(self.test_exe_file_path))
 def test_can_successfully_call_csc_only(self):
     cs_language_with_config = CSLanguage(self.config_parser)
     (ret_code, out,
      err) = shell(cs_language_with_config.compiler_path + " -help")
     self.assertEquals(ret_code, 0)
 def test_can_find_csc(self):
     cs_language_with_config = CSLanguage(self.config_parser)
     (is_found, path) = find_tool("csc")
     self.assertTrue(is_found)
     self.assertEquals(path.pop(0), cs_language_with_config.compiler_path)
class CSLanguageTests(unittest.TestCase):
    def setUp(self):
        self.cs_language_without_config = CSLanguage()
        self.test_file_name = "cs_basic"
        self.test_src_name = self.test_file_name + ".cs"
        self.test_exe_name = self.test_file_name + ".exe"

        self.test_src_file_path = os.path.join(self.src_code_dir,
                                               self.test_src_name)
        self.test_exe_file_path = os.path.join(self.build_dir_bin,
                                               self.test_exe_name)

    def test_are_all_fixture_attributes_set(self):
        assert hasattr(self, "build_dir")
        assert hasattr(self, "build_dir_bin")
        assert hasattr(self, "src_code_dir")
        assert hasattr(self, "config_parser")
        assert hasattr(self, "is_config_read_ok")
        assert hasattr(self, "cs_compiler_path")

    def test_can_find_build_dir_bin(self):
        self.assertTrue(os.path.exists(self.build_dir_bin))

    def test_can_find_test_src_file(self):
        self.assertTrue(os.path.exists(self.test_src_file_path))

    def test_can_create_cs_language_without_config(self):
        self.assertIsNotNone(self.cs_language_without_config)

    def test_cs_language_name(self):
        self.assertEqual(self.cs_language_without_config.get_name(), "C#")

    def test_cs_language_extension(self):
        self.assertEqual(self.cs_language_without_config.get_extension(), "cs")

    def test_can_get_default_cs_compiler_path(self):
        self.assertEquals(self.cs_language_without_config.get_compiler_path(),
                          CSLanguage.DEFAULT_COMPILER_PATH)

    def test_is_default_compiler_path_exists(self):
        self.assertTrue(os.path.exists(self.cs_compiler_path))

    def test_can_find_csc(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (is_found, path) = find_tool("csc")
        self.assertTrue(is_found)
        self.assertEquals(path.pop(0), cs_language_with_config.compiler_path)

    def test_can_successfully_call_csc_only(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (ret_code, out,
         err) = shell(cs_language_with_config.compiler_path + " -help")
        self.assertEquals(ret_code, 0)

    def test_can_successfully_call_csc_to_compile_test_file(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (ret_code, out, err) = self._compile(cs_language_with_config)
        self.assertEquals(ret_code, 0)
        self.assertTrue(os.path.exists(self.test_exe_file_path))

    def test_can_successfully_compile_and_run_test_file(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        self._compile(cs_language_with_config)
        (ret_code, out, err) = shell(self.test_exe_file_path)
        self.assertEquals(ret_code, 0)
        self.assertEquals(split_lines(out).pop(0), "Hello World using C#!")

    def test_can_successfully_compile_and_run_test_file_with_config(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        self._compile(cs_language_with_config)
        (ret_code, out, err) = shell(self.test_exe_file_path)
        self.assertEquals(ret_code, 0)
        self.assertEquals(split_lines(out).pop(0), "Hello World using C#!")

    def _compile(self, language):
        compile_cmd = screen_str(
            language.compiler_path
        ) + " /debug+ /out:" + self.test_exe_file_path + " " + self.test_src_file_path
        return shell(compile_cmd)
class CSLanguageTests(unittest.TestCase):
    def setUp(self):
        self.cs_language_without_config = CSLanguage()
        self.test_file_name = "cs_basic"
        self.test_src_name = self.test_file_name + ".cs"
        self.test_exe_name = self.test_file_name + ".exe"

        self.test_src_file_path = os.path.join(self.src_code_dir, self.test_src_name)
        self.test_exe_file_path = os.path.join(self.build_dir_bin, self.test_exe_name)

    def test_are_all_fixture_attributes_set(self):
        assert hasattr(self, "build_dir")
        assert hasattr(self, "build_dir_bin")
        assert hasattr(self, "src_code_dir")
        assert hasattr(self, "config_parser")
        assert hasattr(self, "is_config_read_ok")
        assert hasattr(self, "cs_compiler_path")

    def test_can_find_build_dir_bin(self):
        self.assertTrue(os.path.exists(self.build_dir_bin))

    def test_can_find_test_src_file(self):
        self.assertTrue(os.path.exists(self.test_src_file_path))

    def test_can_create_cs_language_without_config(self):
        self.assertIsNotNone(self.cs_language_without_config)

    def test_cs_language_name(self):
        self.assertEqual(self.cs_language_without_config.get_name(), "C#")

    def test_cs_language_extension(self):
        self.assertEqual(self.cs_language_without_config.get_extension(), "cs")

    def test_can_get_default_cs_compiler_path(self):
        self.assertEquals(self.cs_language_without_config.get_compiler_path(), CSLanguage.DEFAULT_COMPILER_PATH)

    def test_is_default_compiler_path_exists(self):
        self.assertTrue(os.path.exists(self.cs_compiler_path))

    def test_can_find_csc(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (is_found, path) = find_tool("csc")
        self.assertTrue(is_found)
        self.assertEquals(path.pop(0), cs_language_with_config.compiler_path)

    def test_can_successfully_call_csc_only(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (ret_code, out, err) = shell(cs_language_with_config.compiler_path + " -help")
        self.assertEquals(ret_code, 0)

    def test_can_successfully_call_csc_to_compile_test_file(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        (ret_code, out, err) = self._compile(cs_language_with_config)
        self.assertEquals(ret_code, 0)
        self.assertTrue(os.path.exists(self.test_exe_file_path))

    def test_can_successfully_compile_and_run_test_file(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        self._compile(cs_language_with_config)
        (ret_code, out, err) = shell(self.test_exe_file_path)
        self.assertEquals(ret_code, 0)
        self.assertEquals(split_lines(out).pop(0), "Hello World using C#!")

    def test_can_successfully_compile_and_run_test_file_with_config(self):
        cs_language_with_config = CSLanguage(self.config_parser)
        self._compile(cs_language_with_config)
        (ret_code, out, err) = shell(self.test_exe_file_path)
        self.assertEquals(ret_code, 0)
        self.assertEquals(split_lines(out).pop(0), "Hello World using C#!")

    def _compile(self, language):
        compile_cmd = screen_str(
            language.compiler_path) + " /debug+ /out:" + self.test_exe_file_path + " " + self.test_src_file_path
        return shell(compile_cmd)
 def get_languages_list():
     return [CPPLanguage.get_name(), CSLanguage.get_name(), FPLanguage.get_name()]
 def get_languages_list():
     return [CPPLanguage.get_name(), CSLanguage.get_name(), FPLanguage.get_name()]
Пример #14
0
 def test_can_create_build_bot_for_cs_language(self):
     language = CSLanguage()
     build_bot = BuildBot()
     build_bot.set_language(language)
     self.assertEqual(build_bot.language.compiler_path, self.cs_compiler_path)
 def test_can_get_cs_compiler(self):
     cpp_language = CSLanguage()
     self.assertIsNotNone(cpp_language.get_compiler_path(), CSLanguage.DEFAULT_COMPILER_DIR)