def test_format_date(self) -> NoReturn: date = datetime.utcnow() f_date = Render.format_date(date, quoted=False, sep=False) fq_date = Render.format_date(date, quoted=True, sep=False) fs_date = Render.format_date(date, quoted=False, sep=True) assert f_date.count("\"") == 0 assert fq_date.count("\"") == 2 assert f_date.count(" ") == 2 assert fs_date.count(" ") == 3
def test_functions(self) -> NoReturn: params = self.make_params("func") params['a'] = "alO@)IW)IJW)EWJ)FIJ" def check_rendered(data: str) -> NoReturn: assert data assert isinstance(data, str) assert params['a'] in data with use_mock_loader(): for res in (Render.functions(name="functions/func", **params), Render.functions(name="functions/func.v.jinja", fmt=None, **params)): check_rendered(res)
def generate(self, project_name: str = None, **kwargs) -> object: """ Generates FPGA configs """ if project_name or kwargs: self.setup(project_name=project_name, **kwargs) self.configs = {'LICENSE': Loader.load_static("LICENSE")} self.configs.update( dict( zip( map(lambda x: f"{self.project_name}.{x}", ("v", "qpf", "qsf", "sdc")), (Render.v(self.project_name, assignments=self._v, **self._mips_v), Render.qpf(self.project_name, **self._qpf), Render.qsf(self.project_name, func=self._functions, mips=self._mips_qsf, **self._qsf), Render.sdc(self.project_name, mips=self._mips_type, **self._sdc))))) # NOTE additional modules are placed in separate folder 'functions' self.configs.update( dict( zip( map(lambda x: x + ".v", self._functions), # file paths map(lambda x: Render.functions(x, **self._func), self._functions)))) if self._mips_type: # Generate additional configs for SchoolMIPS program_hex = os.path.join(PATHS.MIPS, "program.hex") self.configs['program.hex'] = Loader.load_static(program_hex) mips_path = os.path.join(PATHS.MIPS, self._mips_type) files = os.listdir(mips_path) self.configs.update( dict( zip( map(lambda x: os.path.join(DESTINATIONS.MIPS, x), files), map(lambda x: Loader.load_static(x, mips_path), files)))) return self
def test__render(self) -> NoReturn: with use_mock_loader(): mock_template = ENV.get_template(MOCK_TEMPL_NAME) strings = { 'a': "LKAJEI_ID(#F)WI#)FJk", 'b': "lKSJE(#-q-wd--3_W(#J", 'c': "!(*@(*)#@*&$))OJDSAI" } res = Render._render(mock_template, **strings) for line, string in zip(res.split('\n'), strings.values()): assert line == string
def test_v(self) -> NoReturn: params = self.make_params("v") self._check_rendered(Render.v(**params), params)
def test_sdc(self) -> NoReturn: params = self.make_params("sdc") res = Render.sdc(**params) assert res and isinstance(res, str)
def test_qsf(self) -> NoReturn: params = self.make_params("qsf") self._check_rendered(Render.qsf(**params), params)