def __process_file(self, fixture, file_path): try: content = unicode(open(file_path).read(), encoding='utf-8') lines = [line.strip() for line in content.split("\n") if len(line)] except IOError: fixture.add_invalid_test_file(file_path) return compiled_conditions_file = os.path.join(os.path.split(file_path)[0], os.path.splitext(file_path)[0] + ".pyc") conditions_file = os.path.join(os.path.split(file_path)[0], os.path.splitext(file_path)[0] + ".py") if os.path.exists(compiled_conditions_file): conditions_module = reflection.get_module_from_path(compiled_conditions_file) elif os.path.exists(conditions_file): conditions_module = reflection.get_module_from_path(conditions_file) else: conditions_module = None self.__process_lines(fixture, file_path, [line.strip() for line in lines if line.strip()], conditions_module)
def test_get_class_in_module(self): klass = ref.get_class_for_module(ref.get_module_from_path(self.module_path), "TestReflection") assert klass.__name__ == TestReflection.__name__ assert klass.return_something() == "something else"
def test_get_classes_for_module(self): classes = ref.get_classes_for_module(ref.get_module_from_path(self.module_path)) assert type(classes) == list assert len(classes) == 1 assert classes[0].__name__ == TestReflection.__name__ assert classes[0].return_something() == "something else"
def test_reflection_get_module_from_path(self): module = ref.get_module_from_path(self.module_path) assert module.__name__ == "test_reflection" assert module.return_something() == "something"