Skip to content

Commit

Permalink
improving bulk performance and test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-st-john committed May 21, 2024
1 parent a2c9124 commit c42a70c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
48 changes: 48 additions & 0 deletions ci.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@echo off

:: Install dependencies
python -m pip install --upgrade pip
python -m pip install flake8 pytest coverage coverage-badge setuptools
python -m pip install -e .
if exist requirements.dev.txt (
python -m pip install -r requirements.dev.txt
)

:: Lint with flake8
:: Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
:: Exit-zero treats all errors as warnings (you may want to adjust this)
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

:: Run tests with pytest and coverage information
coverage run -m pytest .

:: Generate and commit coverage report (if Python version is 3.12)
for /f "tokens=2 delims==" %%i in ('python --version') do set PYTHON_VERSION=%%i
if "%PYTHON_VERSION%" == "3.12" (
set coverage_output=coverage report -m
coverage-badge -o test_coverage.svg -f

:: Configure Git with the author information
git config --global user.email "[email protected]"
git config --global user.name "cole-st-john"

:: Add the test_coverage.svg file to the repository
git add test_coverage.svg

:: Commit the file with a message that includes the coverage output
git commit -m "Updated test coverage badge

Test Coverage Results:

%coverage_output%"

:: Push the changes to the correct branch
git push origin master
)

:: Set GitHub token environment variable (needs to be set beforehand in the system or CI/CD environment)
set GH_TOKEN=%GH_TOKEN%


pause
7 changes: 6 additions & 1 deletion src/yedextended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,8 @@ def create_excel_template(self, type):

self.excel_type_verification(type)

os.remove(self.TEMP_EXCEL_SHEET)
if os.path.isfile(self.TEMP_EXCEL_SHEET):
os.remove(self.TEMP_EXCEL_SHEET)

# create workbook
excel_wb = pyxl.Workbook()
Expand Down Expand Up @@ -1073,8 +1074,12 @@ def wrapper_func(self, *args, **kwargs):
with open(excel_data, "rb") as f:
in_mem_file = io.BytesIO(f.read())
else:
if not os.path.isfile(self.TEMP_EXCEL_SHEET):
self.create_excel_template(type)
sleep(1)
with open(self.TEMP_EXCEL_SHEET, "rb") as f:
in_mem_file = io.BytesIO(f.read())

if not in_mem_file:
raise RuntimeWarning("No excel data found to open.")
self.excel_wb = pyxl.load_workbook(in_mem_file)
Expand Down
6 changes: 3 additions & 3 deletions test_coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/test_yedextended.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ def test_open_yed_file():

def test_init():
excel = yed.ExcelManager()
graph = yed.Graph()
excel.graph_to_excel_conversion(graph=graph)
assert excel is not None
assert os.path.isfile(excel.TEMP_EXCEL_SHEET) is True, "Expected template created"

Expand Down
Binary file added yedextended_temp.xlsx
Binary file not shown.

0 comments on commit c42a70c

Please sign in to comment.