• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python base.BaseCompiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_is_supported

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


示例17: test_should_compile

    def test_should_compile(self):
        compiler = BaseCompiler()
        compiler.get_source_mtime = MagicMock()
        compiler.get_output_mtime = MagicMock()
        compiler.get_dependencies = MagicMock(return_value=["B", "C"])
        mtimes = dict(
            A=1,
            B=3,
            C=5,
        )
        compiler.get_source_mtime.side_effect = lambda x: mtimes[x]

        compiler.get_output_mtime.return_value = None
        self.assertTrue(compiler.should_compile("A"))

        compiler.supports_dependencies = True

        compiler.get_output_mtime.return_value = 6
        self.assertFalse(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 5
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 4
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 2
        self.assertTrue(compiler.should_compile("A"))

        compiler.supports_dependencies = False

        compiler.get_output_mtime.return_value = 2
        self.assertFalse(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 1
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 0
        self.assertTrue(compiler.should_compile("A"))
开发者ID:datanordic,项目名称:django-static-precompiler,代码行数:39,代码来源:test_base_compiler.py


示例18: test_get_output_filename

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


示例19: test_should_compile

    def test_should_compile(self):
        compiler = BaseCompiler()
        compiler.get_source_mtime = MagicMock()
        compiler.get_output_mtime = MagicMock()
        compiler.get_dependencies = MagicMock(return_value=["B", "C"])
        mtimes = dict(
            A=1,
            B=3,
            C=5,
        )
        compiler.get_source_mtime.side_effect = lambda x: mtimes[x]

        compiler.get_output_mtime.return_value = None
        self.assertTrue(compiler.should_compile("A"))

        compiler.supports_dependencies = True

        compiler.get_output_mtime.return_value = 6
        self.assertFalse(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 5
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 4
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 2
        self.assertTrue(compiler.should_compile("A"))

        compiler.supports_dependencies = False

        compiler.get_output_mtime.return_value = 2
        self.assertFalse(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 1
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_output_mtime.return_value = 0
        self.assertTrue(compiler.should_compile("A"))

        compiler.get_source_mtime.reset_mock()
        with patch("static_precompiler.compilers.base.DISABLE_AUTO_COMPILE"):
            self.assertFalse(compiler.should_compile("A"))
            self.assertFalse(compiler.get_source_mtime.called)
开发者ID:vincenzorizza,项目名称:pinseri,代码行数:44,代码来源:test_base_compiler.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.normalize_path函数代码示例发布时间:2022-05-27
下一篇:
Python compilers.SCSS类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap