def translatePackage(self, package, class_translator=None):
     if not class_translator:
         class_translator = ClassToJs(self.context)
     classes_node = AutoTemplateAstNode()
     for class_ in self.package_browser.getExposedClasses(package):
         n = class_translator.translateClass(class_)
         classes_node.translate(class_.__name__, n)
     return classes_node
class ClassToJsUnitTest(SimpleRpcLogicBase):
    '''
    #TODO: document
    '''
    def __post_init__(self):
        self.class_to_js = ClassToJs(self.context)
        self.templates = TemplatesCollector(self.context)
        self.file_manager = FileManager(self.context)

    def translateClass(self, class_):
        '''  '''
        ast_tree = self.class_to_js.translateClass(class_)
        templates_set = 'js_unittest_templates'
        templates = self.templates.collectBuiltIn(templates_set)
        js_str = ast_tree.getString(templates)
        return js_str

    def translateToFile(self, tested_class, file_path, overwrite=False):
        js_str = self.__getClassJsUnit(tested_class)
        #create directory just in case
        test_dir = os.path.dirname(file_path)
        self.file_manager.makedirs(test_dir)
        #Say where it is in a pretty way
        path = self.file_manager.formatFilePath(file_path)
        name = tested_class.__name__
        self.log.d('Creating js for %s test at:\n %s' % (name, path))
        #save file
        self.file_manager.saveTextFile(file_path, js_str, overwrite)

    def __getClassJsUnit(self, tested_class):
        js_str = self.translateClass(tested_class)
        translate = dict(EXPOSED_RPC_API_CLASS=self.context.js_rpc_file)
        js_str = Template(js_str).safe_substitute(translate)
        return js_str
 def __post_init__(self):
     self.class_to_js = ClassToJs(self.context)
     self.templates = TemplatesCollector(self.context)
     self.file_manager = FileManager(self.context)