def test_minifier_available_and_minified_file_not_present_should_not_raise(
        tmpdir, compilers):
    open(str(tmpdir / 'a.js'), 'w').close()
    compilers.add_minifier(MockMinifier())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', minifier='mock')
Пример #2
0
def test_compiler_available_and_source_not_present_should_raise(
    tmpdir, compilers):
    compilers.add_compiler(MockCompiler())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    with pytest.raises(fanstatic.UnknownResourceError) as exc:
        a = Resource(lib, 'a.js', compiler='mock')
    assert 'a.source' in str(exc.value)
def test_compiler_available_and_source_not_present_should_raise(
        tmpdir, compilers):
    compilers.add_compiler(MockCompiler())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    with pytest.raises(fanstatic.UnknownResourceError) as exc:
        a = Resource(lib, 'a.js', compiler='mock')
    assert 'a.source' in str(exc.value)
Пример #4
0
def test_minifier_available_and_minified_file_not_present_should_not_raise(
    tmpdir, compilers):
    open(str(tmpdir / 'a.js'), 'w').close()
    compilers.add_minifier(MockMinifier())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', minifier='mock')
def test_compiler_available_and_resource_file_not_present_should_not_raise(
        tmpdir, compilers):
    open(str(tmpdir / 'a.source'), 'w').close()
    # since the compiler can be used to generate the resource file
    compilers.add_compiler(MockCompiler())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', compiler='mock')
Пример #6
0
def test_compiler_available_and_resource_file_not_present_should_not_raise(
    tmpdir, compilers):
    open(str(tmpdir / 'a.source'), 'w').close()
    # since the compiler can be used to generate the resource file
    compilers.add_compiler(MockCompiler())
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', compiler='mock')
Пример #7
0
def test_compiler_not_available_and_source_not_present_should_raise(
    tmpdir, compilers):
    open(str(tmpdir / 'a.js'), 'w').close()
    compiler = MockCompiler()
    compiler.available = False
    compilers.add_compiler(compiler)
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', compiler='mock')
def test_compiler_not_available_and_source_not_present_should_raise(
        tmpdir, compilers):
    open(str(tmpdir / 'a.js'), 'w').close()
    compiler = MockCompiler()
    compiler.available = False
    compilers.add_compiler(compiler)
    set_resource_file_existence_checking(True)
    lib = Library('lib', str(tmpdir))
    # assert_nothing_raised
    a = Resource(lib, 'a.js', compiler='mock')
Пример #9
0
def test_resource_file_exists(tmpdir):
    tmpdir.join('a.js').write('/* hello world */')
    # by default this is set to False during the tests, but in normal
    # non-test circumstances this is set to True, and we want to
    # test things for real here
    set_resource_file_existence_checking(True)
    foo = Library('foo', tmpdir.strpath)
    # since a.js exists, this should work
    a = Resource(foo, 'a.js')
    # now we try to create a resource that refers to a file
    # that doesn't exist
    with pytest.raises(UnknownResourceError):
        b = Resource(foo, 'b.js')
Пример #10
0
    def setUp(self):
        from fanstatic import Library, Resource
        from fanstatic import set_resource_file_existence_checking
        set_resource_file_existence_checking(False)

        self.lib = Library('foo', '')
        #  When the resources contains an unicode string fanstatic may break
        #  if the HTML is only str.
        self.resource = Resource(self.lib, u'resource.js')

        self.config = testing.setUp()
        self.config.registry.settings.update(self._custom_config)
        self.config.include("pyramid_fanstatic")
        self.config.add_route('home', '/')
        self.config.add_view(route_name='home', view=self.home)
        self.app = TestApp(self.config.make_wsgi_app())
Пример #11
0
def test_resource_file_exists(tmpdir):
    tmpdir.join('a.js').write('/* hello world */')
    # by default this is set to False during the tests, but in normal
    # non-test circumstances this is set to True, and we want to
    # test things for real here
    set_resource_file_existence_checking(True)
    foo = Library('foo', tmpdir.strpath)
    # since a.js exists, this should work
    a = Resource(foo, 'a.js')
    # now we try to create a resource that refers to a file
    # that doesn't exist
    with pytest.raises(UnknownResourceError):
        b = Resource(foo, 'b.js')

    sub_c = tmpdir.mkdir('sub').join('c.css').write('c')
    c = Resource(foo, 'sub/c.css')
Пример #12
0
 def tearDown(self):
     from fanstatic import set_resource_file_existence_checking
     testing.tearDown()
     set_resource_file_existence_checking(True)
Пример #13
0
def pytest_runtest_teardown(item):
    set_resource_file_existence_checking(True)
Пример #14
0
def pytest_runtest_teardown(item):
    set_resource_file_existence_checking(True)
def pytest_runtest_setup(item):
    set_resource_file_existence_checking(False)
    set_auto_register_library(True)
    # Reset the registry before each test.
    get_library_registry().clear()
    thread_local_needed_data.__dict__.pop(NEEDED, None)
def pytest_runtest_teardown(item):
    set_resource_file_existence_checking(True)
    set_auto_register_library(False)
Пример #17
0
def pytest_runtest_setup(item):
    set_resource_file_existence_checking(False)
Пример #18
0
def pytest_runtest_setup(item):
    set_resource_file_existence_checking(False)