Skip to content

Commit

Permalink
Merge pull request #134 from toonarmycaptain/development
Browse files Browse the repository at this point in the history
Development - Test coverage, minor refactors.

- Refactor save_as_dialogue to prevent TypeError.
- Add load_chart_data, refactor load_class_data using load_from_json_file.
- Add new test coverage:
    - load_chart_data
    - save_as_dialogue
    - select_file_dialogue
    - select_folder_dialogue
- Fix circleci test metadata storage.
- Add .bettercodehub.yml

Fixes #92 UI_functions, class_functions_UI now 100% covered by tests.
  • Loading branch information
toonarmycaptain authored Feb 1, 2019
2 parents 14c85e4 + 6c2e12d commit 1deabb9
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 105 deletions.
13 changes: 13 additions & 0 deletions .bettercodehub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
languages:
- python

- name: python
production:
exclude:
- /test_suite/.*

test:
include:
- /test_suite/.*

component_depth: 2
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ jobs:
command: |
. venv/bin/activate
mkdir test-reports
pytest -v --cov=/home/circleci/dionysus/ --junitxml=../test-results/junit.xml
coverage xml
pytest --junitxml=test-reports/junit.xml
- store_test_results:
path: test-results
path: test-reports

- store_artifacts:
path: test-reports
path: test-reports
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Improved test coverage.
- Add load_chart_data, load_json_from_file
- Add .bettercodehub.yml - prevent failed PR checks because of test code.
### Changed
- Fix bug in save_as_dialogue that failed with TypeError when called without filetypes parameter or with default filetypes=None.
- Fix circleci not storing test metadata.
- Refactor save_as_dialogue to prevent TypeError.
- Refactor load_class_data using load_from_json_file.


## [0.3.0-alpha] - 2019-01-23
Expand Down
22 changes: 17 additions & 5 deletions dionysus_app/UI_menus/UI_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def scrub_candidate_filename(dirty_string: str):


def save_as_dialogue(title_str=None,
default_file_type=None,
default_file_extension=None,
filetypes=None,
suggested_filename=None,
start_dir=None
Expand All @@ -81,6 +81,7 @@ def save_as_dialogue(title_str=None,
filetype argument (if provided) eg '*.png'.
title_str is string to be displayed in popup's title bar.
NB if none provided, or is None - title displayed is "Save as".
default_filetype is a string to be added as an extension (eg '.png, but can
be anything (eg 'dead_parrot', '_chart.png' in the event user does not
Expand All @@ -102,8 +103,16 @@ def save_as_dialogue(title_str=None,
Returns None instead of empty string if no file is selected.
NB When default_file_extension is given, but not in filetypes, if
the first filetype in filetypes is NOT ("all files", "*.*"), that
first filetype in filetypes will by appended rather than the default
extension. If ("all files", "*.*") is the first filetype, the
default_file_extension will be appended as expected.
:param title_str: str
:param default_file_type: list
:param default_file_extension: list
:param suggested_filename: str
:param filetypes: list
:param start_dir: str
Expand All @@ -112,17 +121,17 @@ def save_as_dialogue(title_str=None,
root = tk.Tk()
root.withdraw()

if not default_file_type:
if filetypes and not default_file_extension:
# Make extension of first listed filetype default save extension.
first_extension_without_wildcard = filetypes[0][1].strip('*')
if first_extension_without_wildcard != '.':
default_file_type = first_extension_without_wildcard
default_file_extension = first_extension_without_wildcard

default_filetypes = [("all files", "*.*")]
if not filetypes:
filetypes = default_filetypes
filepath_str = filedialog.asksaveasfilename(title=title_str,
defaultextension=default_file_type,
defaultextension=default_file_extension,
filetypes=filetypes,
initialfile=suggested_filename,
initialdir=start_dir,
Expand All @@ -146,6 +155,9 @@ def select_file_dialogue(title_str=None,
Returns None instead of empty string if no file is selected.
NB If no title is passed to filedialog.askopenfilename, the window
title will be "Open".
:param title_str: str
:param filetypes: list
:param start_dir: str
Expand Down
20 changes: 16 additions & 4 deletions dionysus_app/class_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

from dionysus_app.class_registry_functions import register_class
from dionysus_app.data_folder import DataFolder, CLASSLIST_DATA_FILE_TYPE
from dionysus_app.file_functions import convert_to_json, load_from_json, copy_file
from dionysus_app.file_functions import (convert_to_json,
load_from_json_file,
copy_file,
)
from dionysus_app.UI_menus.class_functions_UI import (blank_class_dialogue,
class_data_feedback,
display_class_selection_menu,
Expand Down Expand Up @@ -246,12 +249,21 @@ def load_class_data(class_name: str):
class_data_filename = class_name + CLASSLIST_DATA_FILE_TYPE
classlist_data_path = CLASSLIST_DATA_PATH.joinpath(class_name, class_data_filename)

with open(classlist_data_path, 'r') as class_datafile:
loaded_class_json = class_datafile.read()
class_data_dict = load_from_json(loaded_class_json)
class_data_dict = load_from_json_file(classlist_data_path)
return class_data_dict


def load_chart_data(chart_data_path: str):
"""
Load class data from chart data ('.cdf') file.
:param chart_data_path: Path or str
:return: dict
"""
chart_data_dict = load_from_json_file(chart_data_path)
return chart_data_dict


def get_avatar_path(class_name, student_avatar):
"""
Take value from 'avatar' in list of student data, return path for student avatar or default avatar path if student
Expand Down
13 changes: 13 additions & 0 deletions dionysus_app/file_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ def load_from_json(data_to_convert: str):
return converted_data


def load_from_json_file(json_file_path: str):
"""
Take a filepath and load json from that file.
:param json_file_path: Path (or str)
:return: dict
"""
with open(json_file_path) as json_file:
json_data = json_file.read()
loaded_data = load_from_json(json_data)
return loaded_data


def copy_file(origin_fullpath: str, destination_fullpath: str):
"""
Takes two filepaths, copying the origin file to the destination path and filename.
Expand Down
Loading

0 comments on commit 1deabb9

Please sign in to comment.