Skip to content

Commit a014df6

Browse files
authored
Merge pull request #33 from datacamp/jh/protowhat-refactor
[CX-1182] protowhat refactor
2 parents 225e1b9 + 7cbfb91 commit a014df6

File tree

17 files changed

+151
-93
lines changed

17 files changed

+151
-93
lines changed

.circleci/config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: 2.1
2+
3+
orbs:
4+
python: circleci/python@1.2
5+
6+
jobs:
7+
build-and-test:
8+
docker:
9+
- image: cimg/python:3.12
10+
steps:
11+
- checkout
12+
- run:
13+
name: Install packages
14+
command: make install
15+
- run:
16+
name: Run tests
17+
command: python -m pytest --cov=sheetwhat
18+
publish:
19+
docker:
20+
- image: cimg/python:3.12
21+
steps:
22+
- checkout
23+
- run:
24+
command: |
25+
python setup.py sdist bdist_wheel
26+
pip install pipenv
27+
pipenv install twine
28+
pipenv run twine upload --verbose --repository pypi dist/*
29+
workflows:
30+
pr:
31+
jobs:
32+
- build-and-test:
33+
filters:
34+
branches:
35+
ignore: master
36+
publish:
37+
jobs:
38+
- build-and-test:
39+
filters:
40+
tags:
41+
only: /^v\d+\.\d+\.\d+$/
42+
branches:
43+
ignore: /.*/
44+
- publish:
45+
requires:
46+
- build-and-test
47+
filters:
48+
tags:
49+
only: /^v\d+\.\d+\.\d+$/
50+
branches:
51+
ignore: /.*/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ tests/.DS_Store
7878
# Custom
7979
.pytest_cache/*
8080

81+
# IDE
82+
.idea

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.6.2
1+
3.12.11

.travis.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Controls
2+
.PHONY : commands install clean test
3+
all : commands
4+
5+
## commands : show all commands.
6+
commands :
7+
@grep -h -E '^##' Makefile | sed -e 's/## //g'
8+
9+
install:
10+
pip3.12 install -e .
11+
pip3.12 install -r requirements.txt
12+
13+
## test : run tests.
14+
test :
15+
pytest --cov=sheetwhat
16+
17+
## clean : clean up junk files.
18+
clean :
19+
@rm -rf bin/__pycache__
20+
@find . -name .DS_Store -exec rm {} \;
21+
@find . -name '*~' -exec rm {} \;
22+
@find . -name '*.pyc' -exec rm {} \;

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
44
# sheetwhat
55

6-
[![Build Status](https://travis-ci.org/datacamp/sheetwhat.svg?branch=master)](https://travis-ci.org/datacamp/sheetwhat)
7-
[![codecov](https://codecov.io/gh/datacamp/sheetwhat/branch/master/graph/badge.svg)](https://codecov.io/gh/datacamp/sheetwhat)
86
[![PyPI version](https://badge.fury.io/py/sheetwhat.svg)](https://badge.fury.io/py/sheetwhat)
9-
[![Documentation Status](https://readthedocs.org/projects/sheetwhat/badge/?version=latest)](https://sheetwhat.readthedocs.io/en/latest/?badge=latest)
107
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdatacamp%2Fsheetwhat.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fdatacamp%2Fsheetwhat?ref=badge_shield)
118

129
`sheetwhat` enables you to write Submission Correctness Tests (SCTs) for interactive Spreadsheet exercises on DataCamp.

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# pkg deps
2-
protowhat~=1.8.0
2+
protowhat~=2.3.1
33
attrs~=18.2.0
44
glom~=18.3.1
55

66
# test deps
7-
pytest~=3.7.4
8-
codecov~=2.0.15
9-
pytest-cov~=2.5.1
7+
pytest~=8.1.1
8+
pytest-cov~=6.1.1
109

1110
# doc deps
1211
sphinx~=1.7.7

sheetwhat/State.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from protowhat.Feedback import Feedback
1+
from protowhat.Feedback import FeedbackComponent
22
from protowhat.State import State as BaseState
33
import copy
44

5-
from protowhat.Test import Fail
6-
75
from sheetwhat.selectors import Dispatcher
86

97

@@ -15,26 +13,30 @@ def __init__(
1513
self.solution_data = solution_data
1614
self.sct_range = sct_range
1715
self.reporter = reporter
18-
self.messages = []
16+
self.feedback_context = None
1917
self.creator = None
2018
self.dispatcher = Dispatcher()
2119
self.node_name = "root"
2220
self.force_diagnose = force_diagnose
23-
24-
def report(self, feedback: str):
25-
return self.do_test(Fail(Feedback(feedback)))
21+
self.debug = False
2622

2723
def to_child(self, append_message="", node_name=None, **kwargs):
2824
"""Basic implementation of returning a child state"""
2925
child = copy.deepcopy(self)
3026
for kwarg in kwargs:
3127
setattr(child, kwarg, kwargs[kwarg])
3228
child.node_name = node_name
33-
if not isinstance(append_message, dict):
34-
append_message = {"msg": append_message, "kwargs": {}}
35-
child.messages = [*self.messages, append_message]
29+
if not isinstance(append_message, FeedbackComponent):
30+
append_message = FeedbackComponent(append_message)
31+
child.feedback_context = append_message
3632
return child
3733

34+
def get_feedback(self, conclusion):
35+
return self.feedback_cls(
36+
conclusion,
37+
[state.feedback_context for state in self.state_history],
38+
)
39+
3840
def to_message_exposed_dict(self):
3941
"""This dictionary is passed through to the message formatter. The fields
4042
defined in the dictionary can be replaced by values in the state by using

sheetwhat/Test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from protowhat import selectors
66
from protowhat.Test import Test
7-
from protowhat.Feedback import Feedback
7+
from protowhat.Feedback import FeedbackComponent
88

99
from sheetwhat.utils import is_empty
1010

@@ -16,21 +16,23 @@ def __init__(self, student_data, solution_data, feedback):
1616
self.solution_data = solution_data
1717

1818
def __repr__(self):
19-
return f"{self.__class__.__name__}:" \
20-
f"student data = {self.student_data}" \
19+
return (
20+
f"{self.__class__.__name__}:"
21+
f"student data = {self.student_data}"
2122
f"solution data = {self.solution_data}"
23+
)
2224

2325

2426
def array_element_tests(test, student_data, solution_data, feedback, *args, **kwargs):
2527
tests = []
2628
if not isinstance(student_data, list) or not isinstance(solution_data, list):
27-
# If student data is None; Feedback will be provided by a different test.
29+
# If student data is None; FeedbackComponent will be provided by a different test.
2830
return tests
2931
for i, (element_student_data, element_solution_data) in enumerate(
3032
zip(student_data, solution_data)
3133
):
3234
if isinstance(feedback, str):
33-
item_feedback = Feedback(feedback)
35+
item_feedback = FeedbackComponent(feedback)
3436
else:
3537
item_feedback = copy.deepcopy(feedback)
3638
item_feedback.message = item_feedback.message.format(

sheetwhat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.5.3"
1+
__version__ = "0.6.0"

0 commit comments

Comments
 (0)