Example #1
0
def main():
    for filename in sys.argv[1:]:
        print '> Analyzing %s...' % filename

        source = slurp(filename)
        tree = ast.parse(source, filename=filename)
        # print dump(tree)

        TreeLinker().visit(tree)

        sb = ScopeBuilder()
        top = sb.visit(tree)
        # print top

        for scope, name, nodes in top.walk():
            node = nodes[0]
            if all(is_use, nodes):
                print 'Undefined variable %s at %d:%d' % (name, node.lineno, node.col_offset)
            if not scope.is_class and all(is_write, nodes):
                if name == '__all__' and scope.is_module:
                    continue
                elif scope.exports is not None and name in scope.exports:
                    continue
                elif scope.exports is None and not name.startswith('_'):
                    if isinstance(node, (ast.FunctionDef, ast.ClassDef)) or is_constant(node):
                        continue
                print '%s %s is never used at %d:%d' % \
                      (name_class(node).title(), name, node.lineno, node.col_offset)
Example #2
0
def local_usage(files):
    for _, pyfile in sorted(files.items()):
        for scope, name, nodes in pyfile.scope.walk():
            node = nodes[0]
            if all(is_use, nodes
                   ) and not scope.is_global(name) and not scope.sees_stars:
                print '%s:%d:%d: undefined variable %s' \
                      % (pyfile.filename, node.lineno, node.col_offset, name)
            if not scope.is_class and all(is_write, nodes):
                if name == '_' or scope.is_module and re.search(
                        r'^__\w+__$', name):
                    continue
                elif scope.exports is not None and name in scope.exports:
                    continue
                elif scope.exports is None and not name.startswith(
                        '_') and not is_import(node):
                    continue
                # TODO: check that it is method/classmethod
                elif is_param(node) and name in {
                        'self', 'cls', 'kwargs', 'request'
                }:
                    continue
                # BUG: shows unused import when it's meant for reexport
                print '%s:%d:%d: %s %s is never used' % \
                      (pyfile.filename, node.lineno, node.col_offset, name_class(node), name)
Example #3
0
    def validate_annotations(self, annotations):
        if not all(isinstance(v, str) for v in list(annotations.values())):
            raise serializers.ValidationError(
                "Annotations should be a dict of GSMs -> tag values")

        if not all(
                isinstance(v, (str, int)) for v in list(annotations.keys())):
            raise serializers.ValidationError(
                "Annotations should be a dict of GSMs -> tag values")

        return annotations
Example #4
0
    def as_json(self):
        is_array = compose(isa(int), attrgetter("name"))

        if all(is_array, self.children):
            return [x.as_json() for x in self.children]
        else:
            return {x.name:x.as_json() for x in self.children}
Example #5
0
 def is_named(self, name):
     if all(isa(basestring), [self.name, name]):
         return self.name.lower() == name.lower()
     else:
         # most likely one of the arguments is an int - we get str from
         # the parser but the names (if numerical) are stored as ints
         return str(self.name) == str(name)
Example #6
0
    def as_json(self):
        is_array = compose(isa(int), attrgetter("name"))

        if all(is_array, self.children):
            return [x.as_json() for x in self.children]
        else:
            return {x.name: x.as_json() for x in self.children}
Example #7
0
 def is_named(self, name):
     if all(isa(basestring), [self.name, name]):
         return self.name.lower() == name.lower()
     else:
         # most likely one of the arguments is an int - we get str from
         # the parser but the names (if numerical) are stored as ints
         return str(self.name) == str(name)
Example #8
0
def test_df_colnames(input, transformer, output):
    feature = Feature(input, transformer, output=output)
    mapper = FeatureEngineeringPipeline(feature)
    entities_df = pd.util.testing.makeCustomDataframe(5, 2)
    entities_df.columns = ['foo', 'bar']
    feature_matrix = mapper.fit_transform(entities_df)
    feature_frame = pd.DataFrame(
        feature_matrix,
        columns=mapper.transformed_names_,
        index=entities_df.index,
    )
    assert fy.all(fy.isa(str), feature_frame.columns)
Example #9
0
 def check(self, feature):
     """Check that the feature's `input` is a str or Iterable[str]"""
     input = feature.input
     is_str = isa(str)
     is_nested_str = all_fn(iterable, lambda x: all(is_str, x))
     assert is_str(input) or is_nested_str(input)
Example #10
0
                                    IndexedTestRun(0,None))\
                              .subscribe(lambda itr: print(str(itr.index) + " " + short_log_str(itr.testrun)))

rx_test_customer_changed_appears.scan(lambda acc,tr: IndexedTestRun(acc.index + 1, tr),
                                                IndexedTestRun(0,None))\
                                          .subscribe(lambda itr: print(str(itr.index) + " " + short_log_str(itr.testrun)))

# ------ overall test suite report - for the whole test suite
rx_test_config_object_exists.zip(rx_test_entitlement_object_exists,
                                 rx_test_product_object_exists,
                                 rx_test_subscriptionManager_object_exists,
                                 rx_test_entitlement_status_changed_appears,
                                 rx_test_customer_object_exists,
                                 rx_test_customer_changed_appears,
                                 lambda *args: list(args))\
                            .map(lambda trs: [trs, all(lambda tr: tr.result.status == True, trs)])\
                            .map(lambda x: TestSuite(short_desc = "Tier1 RHSM DBus Test Suite",
                                                     testsuite_id = None,
                                                     testruns = x[0],
                                                     result = Result(status = x[1],
                                                                     msg = "",
                                                                     verifications = [ Verification(status=x[1],msg="")])))\
                            .subscribe(lambda ts: print("------------------------------\n" + short_log_str(ts)))


#rx_test_config_object_exists.subscribe(print)
#rx_test_config_object_exists.subscribe(writeToFile("test-config-object-exists.json"))

# --- feeding of reactive testware by testware events
async def feed(path, stream):
    async with websockets.connect(urljoin(os.getenv('RHSM_SERVICES_URL'),
Example #11
0
def all_isdigit(keyseqs: 'list[str]') -> bool:
    return funcy.all(m.isdigit(), keyseqs)