当前位置: 首页>>代码示例>>Python>>正文


Python base.BaseCompiler类代码示例

本文整理汇总了Python中static_precompiler.compilers.base.BaseCompiler的典型用法代码示例。如果您正苦于以下问题:Python BaseCompiler类的具体用法?Python BaseCompiler怎么用?Python BaseCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BaseCompiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_full_source_path

    def test_get_full_source_path(self):

        compiler = BaseCompiler()

        root = os.path.dirname(__file__)

        self.assertEqual(
            compiler.get_full_source_path("scripts/test.coffee"),
            os.path.join(root, "static", "scripts", "test.coffee"),
        )

        # Source file doesn't exist
        self.assertRaises(
            ValueError,
            lambda: compiler.get_full_source_path("scripts/does-not-exist.coffee")
        )

        self.assertEqual(
            compiler.get_full_source_path("another_test.coffee"),
            os.path.normpath(
                os.path.join(root, "staticfiles_dir", "another_test.coffee")))

        self.assertEqual(
            compiler.get_full_source_path("prefix/another_test.coffee"),
            os.path.normpath(
                os.path.join(root, "staticfiles_dir_with_prefix",
                             "another_test.coffee")))
开发者ID:pombredanne,项目名称:django-static-precompiler,代码行数:27,代码来源:test_base_compiler.py

示例2: test_get_full_output_path

 def test_get_full_output_path(self):
     compiler = BaseCompiler()
     compiler.get_output_path = MagicMock(
         return_value=OUTPUT_DIR + "/dummy.js")
     self.assertEqual(
         compiler.get_full_output_path("dummy.coffee"),
         os.path.join(ROOT, OUTPUT_DIR, "dummy.js"))
开发者ID:pombredanne,项目名称:django-static-precompiler,代码行数:7,代码来源:test_base_compiler.py

示例3: test_write_output

 def test_write_output(self):
     compiler = BaseCompiler()
     output_path = os.path.join(ROOT, OUTPUT_DIR, "dummy.js")
     self.assertFalse(os.path.exists(output_path))
     compiler.get_full_output_path = MagicMock(return_value=output_path)
     compiler.write_output("compiled", "dummy.coffee")
     self.assertTrue(os.path.exists(output_path))
     self.assertEqual(open(output_path).read(), "compiled")
开发者ID:bmcool,项目名称:django-static-precompiler,代码行数:8,代码来源:test_base_compiler.py

示例4: test_get_output_path

 def test_get_output_path(self):
     compiler = BaseCompiler()
     compiler.get_output_filename = MagicMock(
         side_effect=
         lambda source_path: source_path.replace(".coffee", ".js"))
     self.assertEqual(
         compiler.get_output_path("scripts/test.coffee"),
         OUTPUT_DIR + "/scripts/test.js")
开发者ID:pombredanne,项目名称:django-static-precompiler,代码行数:8,代码来源:test_base_compiler.py

示例5: test_get_source_mtime

 def test_get_source_mtime(self):
     compiler = BaseCompiler()
     compiler.get_full_source_path = MagicMock(return_value="dummy.coffee")
     with patch("static_precompiler.compilers.base.get_mtime") as mocked_get_mtime:
         mocked_get_mtime.return_value = 1
         self.assertEqual(compiler.get_source_mtime("dummy.coffee"), 1)
         mocked_get_mtime.assert_called_with("dummy.coffee")
         #noinspection PyUnresolvedReferences
         compiler.get_full_source_path.assert_called_with("dummy.coffee")
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:9,代码来源:test_base_compiler.py

示例6: test_get_output_mtime

 def test_get_output_mtime(self):
     compiler = BaseCompiler()
     compiler.get_full_output_path = MagicMock(return_value="dummy.js")
     with patch("os.path.exists") as mocked_os_path_exists:
         mocked_os_path_exists.return_value = False
         self.assertEqual(compiler.get_output_mtime("dummy.coffee"), None)
         mocked_os_path_exists.assert_called_with("dummy.js")
         mocked_os_path_exists.return_value = True
         with patch("static_precompiler.compilers.base.get_mtime") as mocked_get_mtime:
             mocked_get_mtime.return_value = 1
             self.assertEqual(compiler.get_output_mtime("dummy.coffee"), 1)
             mocked_get_mtime.assert_called_with("dummy.js")
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:12,代码来源:test_base_compiler.py

示例7: test_get_dependents

    def test_get_dependents(self):
        compiler = BaseCompiler()
        self.assertFalse(Dependency.objects.exists())

        self.assertEqual(
            compiler.get_dependents("spam.scss"),
            [],
        )

        Dependency.objects.create(source="ham.scss", depends_on="spam.scss")
        Dependency.objects.create(source="eggs.scss", depends_on="spam.scss")

        self.assertEqual(
            compiler.get_dependents("spam.scss"),
            [u"eggs.scss", u"ham.scss"],
        )
开发者ID:pombredanne,项目名称:django-static-precompiler,代码行数:16,代码来源:test_base_compiler.py

示例8: test_compile_lazy

    def test_compile_lazy(self):
        compiler = BaseCompiler()
        compiler.compile = MagicMock()
        compiler.compile.return_value = "dummy.js"

        lazy_compiled = compiler.compile_lazy("dummy.coffee")

        # noinspection PyUnresolvedReferences
        self.assertEqual(compiler.compile.call_count, 0)

        self.assertEqual(str(lazy_compiled), "dummy.js")

        # noinspection PyUnresolvedReferences
        self.assertEqual(compiler.compile.call_count, 1)
        # noinspection PyUnresolvedReferences
        compiler.compile.assert_called_with("dummy.coffee")
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:16,代码来源:test_base_compiler.py

示例9: test_get_full_source_path

    def test_get_full_source_path(self):

        compiler = BaseCompiler()

        # Source file in STATIC_ROOT
        self.assertEqual(
            compiler.get_full_source_path("scripts/test.coffee"),
            os.path.join(self.django_settings.STATIC_ROOT, "scripts/test.coffee"),
        )

        # Source file doesn't exist
        self.assertRaises(
            ValueError,
            lambda: compiler.get_full_source_path("scripts/does-not-exist.coffee")
        )

        self.assertEqual(self.django_settings.DEBUG, True)

        self.assertEqual(
            compiler.get_full_source_path("another_test.coffee"),
            os.path.normpath(
                os.path.join(
                    self.django_settings.STATIC_ROOT,
                    "..",
                    "staticfiles_dir",
                    "another_test.coffee"
                )
            )
        )

        self.assertEqual(
            compiler.get_full_source_path("prefix/another_test.coffee"),
            os.path.normpath(
                os.path.join(
                    self.django_settings.STATIC_ROOT,
                    "..",
                    "staticfiles_dir_with_prefix",
                    "another_test.coffee"
                )
            )
        )
开发者ID:bmcool,项目名称:django-static-precompiler,代码行数:41,代码来源:test_base_compiler.py

示例10: test_update_dependencies

    def test_update_dependencies(self):
        compiler = BaseCompiler()

        self.assertFalse(Dependency.objects.exists())

        compiler.update_dependencies("A", ["B", "C"])
        self.assertEqual(
            sorted(Dependency.objects.values_list("source", "depends_on")),
            [("A", "B"), ("A", "C")]
        )

        compiler.update_dependencies("A", ["B", "C", "D"])
        self.assertEqual(
            sorted(Dependency.objects.values_list("source", "depends_on")),
            [("A", "B"), ("A", "C"), ("A", "D")]
        )

        compiler.update_dependencies("A", ["E"])
        self.assertEqual(
            sorted(Dependency.objects.values_list("source", "depends_on")),
            [("A", "E")]
        )

        compiler.update_dependencies("B", ["C"])
        self.assertEqual(
            sorted(Dependency.objects.values_list("source", "depends_on")),
            [("A", "E"), ("B", "C")]
        )

        compiler.update_dependencies("A", [])
        self.assertEqual(
            sorted(Dependency.objects.values_list("source", "depends_on")),
            [("B", "C")]
        )
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:34,代码来源:test_base_compiler.py

示例11: test_find_dependencies

 def test_find_dependencies(self):
     compiler = BaseCompiler()
     self.assertRaises(
         NotImplementedError,
         lambda: compiler.find_dependencies("dummy.coffee")
     )
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:6,代码来源:test_base_compiler.py

示例12: test_compile

    def test_compile(self):
        compiler = BaseCompiler()
        compiler.is_supported = MagicMock()
        compiler.should_compile = MagicMock()
        compiler.compile_file = MagicMock(return_value="compiled")
        compiler.write_output = MagicMock()
        compiler.get_output_path = MagicMock(return_value="dummy.js")
        compiler.postprocess = MagicMock(
            side_effect=lambda compiled, source_path: compiled
        )
        compiler.update_dependencies = MagicMock()
        compiler.find_dependencies = MagicMock(return_value=["A", "B"])

        compiler.is_supported.return_value = False
        self.assertRaises(ValueError, lambda: compiler.compile("dummy.coffee"))

        self.assertEqual(compiler.compile_file.call_count, 0)
        self.assertEqual(compiler.postprocess.call_count, 0)
        self.assertEqual(compiler.write_output.call_count, 0)

        compiler.is_supported.return_value = True
        compiler.should_compile.return_value = False
        self.assertEqual(compiler.compile("dummy.coffee"), "dummy.js")

        self.assertEqual(compiler.compile_file.call_count, 0)
        self.assertEqual(compiler.postprocess.call_count, 0)
        self.assertEqual(compiler.write_output.call_count, 0)

        compiler.should_compile.return_value = True
        self.assertEqual(compiler.compile("dummy.coffee"), "dummy.js")

        self.assertEqual(compiler.compile_file.call_count, 1)
        compiler.compile_file.assert_called_with("dummy.coffee")

        self.assertEqual(compiler.postprocess.call_count, 1)
        compiler.postprocess.assert_called_with("compiled", "dummy.coffee")

        self.assertEqual(compiler.write_output.call_count, 1)
        compiler.write_output.assert_called_with("compiled", "dummy.coffee")

        self.assertEqual(compiler.update_dependencies.call_count, 0)

        compiler.supports_dependencies = True
        compiler.compile("dummy.coffee")
        compiler.find_dependencies.assert_called_with("dummy.coffee")
        compiler.update_dependencies.assert_called_with("dummy.coffee", ["A", "B"])
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:46,代码来源:test_base_compiler.py

示例13: test_postprocess

 def test_postprocess(self):
     compiler = BaseCompiler()
     self.assertEqual(compiler.postprocess("compiled", "dummy.coffee"), "compiled")
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:3,代码来源:test_base_compiler.py

示例14: test_compile_source

 def test_compile_source(self):
     compiler = BaseCompiler()
     self.assertRaises(
         NotImplementedError,
         lambda: compiler.compile_source("source")
     )
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:6,代码来源:test_base_compiler.py

示例15: test_get_source

 def test_get_source(self):
     compiler = BaseCompiler()
     self.assertEqual(
         compiler.get_source("scripts/test.coffee"),
         'console.log "Hello, World!"'
     )
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:6,代码来源:test_base_compiler.py


注:本文中的static_precompiler.compilers.base.BaseCompiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。