示例#1
0
 def test_extra_imports_are_added(self):
     extra_imports = "import thing; import stuff"
     determine_imports(
         extra_imports=extra_imports, with_default_imports=False, without_should_dsl=True
     ) |should| equal_to([
         (NAME, 'import'), (NAME, 'thing'), (OP, ';'), (NAME, 'import'), (NAME, 'stuff')
     ])
示例#2
0
 def test_extra_imports_are_added(self):
     extra_imports = "import thing; import stuff"
     determine_imports(extra_imports=extra_imports,
                       with_default_imports=False,
                       without_should_dsl=True) | should | equal_to(
                           [(NAME, 'import'), (NAME, 'thing'), (OP, ';'),
                            (NAME, 'import'), (NAME, 'stuff')])
示例#3
0
 def test_extra_imports_added_before_defaults(self):
     extra_imports = "import thing; import stuff"
     determine_imports(extra_imports=extra_imports,
                       with_default_imports=True,
                       without_should_dsl=True) | should | equal_to([
                           (NAME, 'import'),
                           (NAME, 'thing'),
                           (OP, ';'),
                           (NAME, 'import'),
                           (NAME, 'stuff'),
                           (OP, ';')  # Extra semicolon inserted
                           ,
                           (NAME, 'import'),
                           (NAME, 'nose'),
                           (OP, ';'),
                           (NAME, 'from'),
                           (NAME, 'nose'),
                           (OP, '.'),
                           (NAME, 'tools'),
                           (NAME, 'import'),
                           (OP, '*'),
                           (OP, ';'),
                           (NAME, 'from'),
                           (NAME, 'noseOfYeti'),
                           (OP, '.'),
                           (NAME, 'tokeniser'),
                           (OP, '.'),
                           (NAME, "support"),
                           (NAME, 'import'),
                           (OP, '*')
                       ])
示例#4
0
 def test_extra_imports_not_added_if_no_defaults(self):
     determine_imports(with_default_imports=True) | should | equal_to(
         [(NAME, 'import'), (NAME, 'nose'), (OP, ';'), (NAME, 'from'),
          (NAME, 'nose'), (OP, '.'), (NAME, 'tools'), (NAME, 'import'),
          (OP, '*'), (OP, ';'), (NAME, 'from'), (NAME, 'noseOfYeti'),
          (OP, '.'), (NAME, 'tokeniser'), (OP, '.'), (NAME, "support"),
          (NAME, 'import'), (OP, '*')])
示例#5
0
 def test_extra_imports_not_added_if_no_defaults(self):
     determine_imports(with_default_imports=True, without_should_dsl=True) |should| equal_to([
           (NAME, 'import'), (NAME, 'nose'), (OP, ';')
         , (NAME, 'from'), (NAME, 'nose'), (OP, '.'), (NAME, 'tools'), (NAME, 'import'), (OP, '*'), (OP, ';')
         , (NAME, 'from')
             , (NAME, 'noseOfYeti'), (OP, '.'), (NAME, 'tokeniser'), (OP, '.'), (NAME, "support")
             , (NAME, 'import'), (OP, '*')
     ])
示例#6
0
 def test_should_dsl_imports_added_if_specified(self):
     determine_imports(with_default_imports=True, without_should_dsl=False) |should| equal_to([
           (NAME, 'import'), (NAME, 'nose'), (OP, ';')
         , (NAME, 'from'), (NAME, 'nose'), (OP, '.'), (NAME, 'tools'), (NAME, 'import'), (OP, '*'), (OP, ';')
         , (NAME, 'from'), (NAME, 'should_dsl'), (NAME, 'import'), (OP, '*'), (OP, ';')
         , (NAME, 'from')
             , (NAME, 'noseOfYeti'), (OP, '.'), (NAME, 'tokeniser'), (OP, '.'), (NAME, "support")
             , (NAME, 'import'), (OP, '*')
     ])
示例#7
0
 def test_should_dsl_imports_added_if_specified(self):
     determine_imports(with_default_imports=True,
                       without_should_dsl=False) | should | equal_to(
                           [(NAME, 'import'), (NAME, 'nose'), (OP, ';'),
                            (NAME, 'from'), (NAME, 'nose'), (OP, '.'),
                            (NAME, 'tools'), (NAME, 'import'), (OP, '*'),
                            (OP, ';'), (NAME, 'from'), (NAME, 'should_dsl'),
                            (NAME, 'import'), (OP, '*'), (OP, ';'),
                            (NAME, 'from'), (NAME, 'noseOfYeti'), (OP, '.'),
                            (NAME, 'tokeniser'), (OP, '.'),
                            (NAME, "support"), (NAME, 'import'), (OP, '*')])
示例#8
0
 def test_extra_imports_added_before_defaults(self):
     extra_imports = "import thing; import stuff"
     determine_imports(
         extra_imports=extra_imports, with_default_imports=True, without_should_dsl=True
     ) |should| equal_to([
           (NAME, 'import'), (NAME, 'thing'), (OP, ';'), (NAME, 'import'), (NAME, 'stuff')
         , (OP, ';') # Extra semicolon inserted
         , (NAME, 'import'), (NAME, 'nose'), (OP, ';')
         , (NAME, 'from'), (NAME, 'nose'), (OP, '.'), (NAME, 'tools'), (NAME, 'import'), (OP, '*'), (OP, ';')
         , (NAME, 'from')
             , (NAME, 'noseOfYeti'), (OP, '.'), (NAME, 'tokeniser'), (OP, '.'), (NAME, "support")
             , (NAME, 'import'), (OP, '*')
     ])
示例#9
0
def register_from_options(options=None, template=None, extractor=None):
    """Register the spec codec using the provided options"""
    if template is None:
        from noseOfYeti.plugins.support.spec_options import spec_options as template

    if extractor is None:
        from noseOfYeti.plugins.support.spec_options import extract_options_dict as extractor

    config = Config(template)
    config.setup(options, extractor)

    imports = determine_imports(
        extra_imports=';'.join([d for d in config.extra_import if d]),
        with_default_imports=config.with_default_imports)

    tok = Tokeniser(default_kls=config.default_kls,
                    import_tokens=imports,
                    wrapped_setup=config.wrapped_setup,
                    with_describe_attrs=not config.no_describe_attrs)

    TokeniserCodec(tok).register()
示例#10
0
def register_from_options(options=None, template=None, extractor=None):
    """Register the spec codec using the provided options"""
    if template is None:
        from noseOfYeti.plugins.support.spec_options import spec_options as template

    if extractor is None:
        from noseOfYeti.plugins.support.spec_options import extract_options_dict as extractor

    config = Config(template)
    config.setup(options, extractor)

    imports = determine_imports(
          extra_imports = ';'.join([d for d in config.extra_import if d])
        , with_default_imports = config.with_default_imports
        )

    tok = Tokeniser(
          default_kls = config.default_kls
        , import_tokens = imports
        , wrapped_setup = config.wrapped_setup
        , with_describe_attrs = not config.no_describe_attrs
        )

    TokeniserCodec(tok).register()
示例#11
0
 def test_it_returns_nothing_if_no_imports(self):
     determine_imports(with_default_imports=False, without_should_dsl=True) |should| equal_to([])
示例#12
0
 def test_it_returns_nothing_if_no_imports(self):
     determine_imports(with_default_imports=False,
                       without_should_dsl=True) | should | equal_to([])