Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plain text input param and calc length estimate improvement #30

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

youandvern
Copy link
Owner

@youandvern youandvern commented Oct 27, 2024

Add plain text option for select input fields
Improve calculation length estimate for negative constants
Update docs and add new release version

Summary by Sourcery

Introduce a plain text option for input fields and enhance the calculation length estimation for negative constants. Update the documentation to version 1.2.6 and add tests for the new features.

New Features:

  • Add a plain text option for input fields to display values as plain text instead of formatted as LaTeX math.

Enhancements:

  • Improve the calculation length estimation to handle negative constants more accurately.

Documentation:

  • Update documentation to reflect changes in input options and calculation length estimation.
  • Bump the documentation version from 1.2.4 to 1.2.6.

Tests:

  • Add tests to verify the new plain text input feature and improved calculation length estimation for negative numbers.

Improve calculation length estimate for negative constants
Update docs and add new release version
Copy link

sourcery-ai bot commented Oct 27, 2024

Reviewer's Guide by Sourcery

This pull request implements two main features: adds a plain text display option for select input fields and improves the calculation length estimation for negative constants. The changes also include documentation updates and a version bump from 1.2.4 to 1.2.6.

Updated class diagram for the Input class

classDiagram
    class Input {
        - str variable_name
        - int|float|str default_value = 0
        - str unit = None
        - str description = None
        - str reference = None
        - Literal['number', 'text', 'select'] input_type = 'number'
        - list select_options = None
        - int|float min_value = None
        - int|float max_value = None
        - int|float|str num_step = 'any'
        - bool plain_text_value = False
    }
Loading

Updated class diagram for the Calculation class

classDiagram
    class Calculation {
        + _get_symbolic_string() str
        + _get_result_string() str
        + estimate_display_length() CalculationLength
    }
Loading

File-Level Changes

Change Details Files
Add plain text display option for input values
  • Add new plain_text_value boolean parameter to Input class
  • Implement text value formatting using \text{} LaTeX command when plain_text_value is True
  • Add unit tests for plain text value display
efficalc/base_definitions/input.py
tests/test_generate_html.py
Improve calculation length estimation for negative constants
  • Add result string comparison to length estimation logic
  • Add symbolic string comparison with result value
  • Add unit tests for negative number length estimation
efficalc/base_definitions/calculation.py
tests/base_definitions/test_calculation.py
Update documentation and version number
  • Update version number from 1.2.4 to 1.2.6
  • Add documentation for plain_text_value parameter
  • Update all documentation files with new version number
docs/base_classes.html
docs/_static/documentation_options.js
docs_src/conf.py
docs/*.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @youandvern - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +341 to +345
def test_input_plain_text(common_setup_teardown):
a = Input("calc", "No & no", plain_text_value=True)
result = generate_html_for_calc_items([a])
assert a.name in result
assert r"\text{No & no}" in result
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test for plain text input should verify HTML escaping more thoroughly

Consider adding more test cases with different special characters that need HTML escaping (e.g. <, >, ", etc) to ensure the plain text input handles all HTML special characters correctly.

def test_input_plain_text(common_setup_teardown):
    test_cases = [
        ("No & no", r"\text{No &amp; no}"),
        ("a < b > c", r"\text{a &lt; b &gt; c}"),
        ('Text "quoted"', r'\text{Text &quot;quoted&quot;}'),
    ]
    for input_text, expected in test_cases:
        a = Input("calc", input_text, plain_text_value=True)
        result = generate_html_for_calc_items([a])
        assert a.name in result
        assert expected in result

Comment on lines 128 to 134
if self._get_display_type() != InputDisplayType.NUMBER:
return rf"\mathrm{{{self.name}}} = \mathrm{{{self.value}}} \ {self.unit}"
text_value = (
rf"\text{{{self.value}}}" if self.plain_text_value else self.value
)
return rf"\mathrm{{{self.name}}} = \mathrm{{{text_value}}} \ {self.unit}"
else:
return super().__str__()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

@youandvern youandvern merged commit 78806ef into main Oct 27, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant