def test_eval(self): with tempfile.TemporaryDirectory() as tempdir: eval_data = [1, 2, 3, 'hi', ['oi']] file = FileIO.create(Path(tempdir).join(self.file.name), eval_data) self.assertEqual(file.data, eval_data) file.save() file = FileIO.load(file.path) self.assertEqual(file.data, eval_data)
def _add_license(base_dir, ext='.py'): from cereja.file import FileIO from cereja.config import BASE_DIR licence_file = FileIO.load(BASE_DIR) for file in FileIO.load_files(base_dir, ext=ext, recursive=True): if 'Copyright (c) 2019 The Cereja Project' in file.string: continue file.insert('"""\n' + licence_file.string + '\n"""') file.save(exist_ok=True)
def test_sanity(self): console.log(f'Testing {self.name}') with tempfile.TemporaryDirectory() as tempdir: self.file.set_path(Path(tempdir).join(self.file.name)) data_before_save = self.file.data self.file.save(exist_ok=True) file = FileIO.load(self.file.path, **self.load_kwargs) self.assertTrue(file.path.exists, msg="File don't exist.") self.assertEqual(file.data, data_before_save, msg='Data corrupted') file.delete() self.assertFalse(file.path.exists)
def load_from_json(cls, path_: str): data = FileIO.load(path_) return cls(data.data, load_mode=True)
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import argparse import sys from cereja import get_version_pep440_compliant, Path from cereja.config import BASE_DIR from cereja.file import FileIO if __name__ == "__main__": sys.stdout.write("\U0001F352 Cereja Tools\n") sys.stdout.flush() parser = argparse.ArgumentParser(description='Cereja Tools.') parser.add_argument('--version', action='version', version=get_version_pep440_compliant()) parser.add_argument('--startmodule', type=str) args = parser.parse_args() if args.startmodule: base_dir = Path(BASE_DIR) license_ = b''.join(FileIO.load( base_dir.parent.join('LICENSE')).data).decode() license_ = '"""\n' + license_ + '"""' new_module_path = base_dir.join(*args.startmodule.split('/')) if new_module_path.parent.exists and new_module_path.parent.is_dir: FileIO.create(new_module_path, license_).save() else: print(f"{new_module_path} is not valid.")