From bd9f1da3e57ce2c1a66f19ea508339eabe237d1e Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Tue, 28 Jan 2025 17:01:00 +0100 Subject: [PATCH 1/3] Create a new file from the Python API --- .../jupytergis_lab/jupytergis_lab/notebook/gis_document.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py b/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py index e8e672bc9..dbdc38ef3 100644 --- a/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py +++ b/python/jupytergis_lab/jupytergis_lab/notebook/gis_document.py @@ -2,6 +2,7 @@ import json import logging +import os from pathlib import Path from typing import Any, Dict, List, Literal, Optional, Union from uuid import uuid4 @@ -63,6 +64,11 @@ def __init__( comm_metadata = GISDocument._path_to_comm(path) + # Create an empty project file if it does not exist + if comm_metadata["path"] and not os.path.isfile(comm_metadata["path"]): + with open(comm_metadata["path"], "w") as fd: + fd.write("{}") + ydoc = Doc() super().__init__( From 3d8076fc96b1f4d88aa6ba319071d8a6c46717f5 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Tue, 28 Jan 2025 17:48:15 +0100 Subject: [PATCH 2/3] Add test on file creation --- .../jupytergis_lab/notebook/tests/test_api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py b/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py index d6a6dc5c5..1c83b8e62 100644 --- a/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py +++ b/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py @@ -1,7 +1,23 @@ +import os import unittest from jupytergis_lab import GISDocument +class ProjectCreation(unittest.TestCase): + filename = "test.jgis" + + def setUp(self): + if os.path.isfile(self.filename): + os.remove(self.filename) + + def tearDown(self): + if os.path.isfile(self.filename): + os.remove(self.filename) + + def test_creation(self): + self.doc = GISDocument(self.filename) + + assert os.path.isfile(self.filename) class VectorTileTests(unittest.TestCase): def setUp(self): From 2b438c941c7dd898b95848acd338342fb9ed8f55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 16:50:06 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py b/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py index 1c83b8e62..6a0a3476c 100644 --- a/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py +++ b/python/jupytergis_lab/jupytergis_lab/notebook/tests/test_api.py @@ -3,6 +3,7 @@ from jupytergis_lab import GISDocument + class ProjectCreation(unittest.TestCase): filename = "test.jgis" @@ -19,6 +20,7 @@ def test_creation(self): assert os.path.isfile(self.filename) + class VectorTileTests(unittest.TestCase): def setUp(self): self.doc = GISDocument()