예제 #1
0
def test(func):
    @functools.wraps(func)
    def run_test(*args, **kwargs):
        with temporary_xdg_cache_dir():
            return func(*args, **kwargs)

    return istest(run_test)
def test(func):
    @functools.wraps(func)
    def run_test():
        with _start_server():
            func()

    return istest(run_test)
예제 #3
0
파일: support.py 프로젝트: npryce/deft
 def decorator(test_func):
     @wraps(test_func)
     def run_with_environment():
         env = environment(test_func.__module__ + "." + test_func.func_name)
         test_func(env)
         
     environment.attribute(run_with_environment)
     return istest(run_with_environment)
예제 #4
0
파일: support.py 프로젝트: jstrachan/deft
def systest(test_func, environment=_selected_environment):
    @wraps(test_func)
    def run_with_environment():
        env = environment(test_func.__module__ + "." + test_func.func_name)
        test_func(env)
    
    environment.attribute(run_with_environment)
    return istest(run_with_environment)
예제 #5
0
 def wrap(func):
     @functools.wraps(func)
     def run_test():
         for vcs in map(VcsUnderTest, all_systems):
             test_params = [kwargs["{0}_params".format(vcs.name)][param_name] for param_name in params]
             with temporary_empty_dir() as temp_dir:
                 yield tuple([test(func), vcs, temp_dir] + test_params)
     return istest(run_test)
 def wrap(function):
     function = istest(function)
     @wraps(function)
     def wrapper(*args, **kwargs):
         initial_resources = resourceconfiguration.resource_configuration.resource_definitions
         resourceconfiguration.resource_configuration.resource_definitions = resources
         try:
             function(*args, **kwargs)
         finally:
             resourceconfiguration.resource_configuration.resource_definitions = initial_resources
     return wrapper
예제 #7
0
def test(func):
    @functools.wraps(func)
    def run_test():
        with create_temporary_dir() as temp_dir:
            def start(commands):
                run_dir = os.path.join(temp_dir, str(uuid.uuid4()))
                return processes.start(commands, run_dir)
            
            return func(start)
    
    return istest(run_test)
예제 #8
0
    def wrap(func):
        @functools.wraps(func)
        def run_test():
            for vcs in map(VcsUnderTest, all_systems):
                test_params = [
                    kwargs["{0}_params".format(vcs.name)][param_name]
                    for param_name in params
                ]
                with temporary_empty_dir() as temp_dir:
                    yield tuple([test(func), vcs, temp_dir] + test_params)

        return istest(run_test)
def test(function):
    function = istest(function)
    @wraps(function)
    def wrapper(*args, **kwargs):
        server_thread = ApplicationServerThread()
        server_thread.start()
        try:
            function(*args, **kwargs)
        finally:
            server_thread.stop()
            server_thread.join()
    return wrapper
예제 #10
0
class RunTests(object):
    @istest
    def run_has_no_style_if_it_has_no_properties(self):
        element = xml_element("w:r")
        assert_equal(None, _read_and_get_document_xml_element(element).style_id)

    @istest
    def run_has_style_id_and_name_read_from_run_properties_if_present(self):
        style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})

        styles = Styles.create(
            character_styles={"Heading1Char": Style(style_id="Heading1Char", name="Heading 1 Char")},
        )

        run = self._read_run_with_properties([style_xml], styles=styles)
        assert_equal("Heading1Char", run.style_id)
        assert_equal("Heading 1 Char", run.style_name)

    @istest
    def warning_is_emitted_when_run_style_cannot_be_found(self):
        style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})
        properties_xml = xml_element("w:rPr", {}, [style_xml])
        run_xml = xml_element("w:r", {}, [properties_xml])

        result = _read_document_xml_element(run_xml, styles=Styles.EMPTY)
        run = result.value
        assert_equal("Heading1Char", run.style_id)
        assert_equal(None, run.style_name)
        assert_equal([results.warning("Run style with ID Heading1Char was referenced but not defined in the document")], result.messages)


    @istest
    def run_is_not_bold_if_bold_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(False, run.is_bold)

    @istest
    def run_is_bold_if_bold_element_is_present(self):
        run = self._read_run_with_properties([xml_element("w:b")])
        assert_equal(True, run.is_bold)

    @istest
    def run_is_not_italic_if_italic_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(False, run.is_italic)

    @istest
    def run_is_italic_if_italic_element_is_present(self):
        run = self._read_run_with_properties([xml_element("w:i")])
        assert_equal(True, run.is_italic)

    @istest
    def run_is_not_underlined_if_underline_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(False, run.is_underline)

    @istest
    def run_is_underlined_if_underline_element_is_present(self):
        run = self._read_run_with_properties([xml_element("w:u")])
        assert_equal(True, run.is_underline)

    @istest
    def run_is_not_struckthrough_if_strikethrough_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(False, run.is_strikethrough)

    @istest
    def run_is_struckthrough_if_strikethrough_element_is_present(self):
        run = self._read_run_with_properties([xml_element("w:strike")])
        assert_equal(True, run.is_strikethrough)

    @istest
    def run_is_not_small_caps_if_small_caps_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(False, run.is_small_caps)

    @istest
    def run_is_small_caps_if_small_caps_element_is_present(self):
        run = self._read_run_with_properties([xml_element("w:smallCaps")])
        assert_equal(True, run.is_small_caps)

    run_boolean_property_test = lambda func: parameterized([
        param(attr_name="is_bold", tag_name="w:b"),
        param(attr_name="is_underline", tag_name="w:u"),
        param(attr_name="is_italic", tag_name="w:i"),
        param(attr_name="is_strikethrough", tag_name="w:strike"),
        param(attr_name="is_small_caps", tag_name="w:smallCaps"),
    ])(istest(func))

    @run_boolean_property_test
    def run_boolean_property_is_false_if_element_is_present_and_val_is_false(self, attr_name, tag_name):
        run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "false"})])
        assert_equal(False, getattr(run, attr_name))

    @run_boolean_property_test
    def run_boolean_property_is_false_if_element_is_present_and_val_is_0(self, attr_name, tag_name):
        run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "0"})])
        assert_equal(False, getattr(run, attr_name))

    @run_boolean_property_test
    def run_boolean_property_is_true_if_element_is_present_and_val_is_true(self, attr_name, tag_name):
        run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "true"})])
        assert_equal(True, getattr(run, attr_name))

    @run_boolean_property_test
    def run_boolean_property_is_true_if_element_is_present_and_val_is_1(self, attr_name, tag_name):
        run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "1"})])
        assert_equal(True, getattr(run, attr_name))

    @istest
    def run_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self):
        run = self._read_run_with_properties([])
        assert_equal(documents.VerticalAlignment.baseline, run.vertical_alignment)

    @istest
    def run_has_vertical_alignment_read_from_vertical_alignment_element(self):
        run = self._read_run_with_properties([xml_element("w:vertAlign", {"w:val": "superscript"})])
        assert_equal(documents.VerticalAlignment.superscript, run.vertical_alignment)

    @istest
    def run_has_none_font_by_default(self):
        run = self._read_run_with_properties([])
        assert_equal(None, run.font)

    @istest
    def run_has_font_read_from_properties(self):
        font_xml = xml_element("w:rFonts", {"w:ascii": "Arial"})
        run = self._read_run_with_properties([font_xml])
        assert_equal("Arial", run.font)

    @istest
    def run_has_none_font_size_by_default(self):
        run = self._read_run_with_properties([])
        assert_equal(None, run.font_size)

    @istest
    def run_has_font_size_read_from_properties(self):
        font_size_xml = xml_element("w:sz", {"w:val": "28"})
        run = self._read_run_with_properties([font_size_xml])
        assert_equal(14, run.font_size)

    @istest
    def run_with_invalid_w_sz_has_none_font_size(self):
        font_size_xml = xml_element("w:sz", {"w:val": "28a"})
        run = self._read_run_with_properties([font_size_xml])
        assert_equal(None, run.font_size)

    def _read_run_with_properties(self, properties, styles=None):
        properties_xml = xml_element("w:rPr", {}, properties)
        run_xml = xml_element("w:r", {}, [properties_xml])
        return _read_and_get_document_xml_element(run_xml, styles=styles)
예제 #11
0
파일: base.py 프로젝트: yougov/influxproxy
def asynctest(f):
    return wraps(f)(istest(unittest_run_loop(f)))
예제 #12
0
def test(func):
    @functools.wraps(func)
    def run_test(*args, **kwargs):
        with temporary_xdg_cache_dir():
            return func(*args, **kwargs)
    return istest(run_test)