Implement UnitTesting for UI Units handling, and improve it #39267

Closed
opened 2014-03-19 16:37:42 +01:00 by Bastien Montagne · 4 comments

Implement UnitTesting for UI Units handling, and improve it

So, related to #38722 and proposed fix (D340), I talked a bit with Campbell and he suggested to first expose 'units' in bpy, and create a test for it.

Test should gather a bunch of expressions and their desired result, to check what's currently working, what’s currently broken, and how this change when we modify underlying C code.

I made a quick prototype for this: D416. For now, it only contains trivial tests (two input, one know as broken, and one output). The main purpose of this design task is to gather a representative set of inputs (text to value) and outputs (value to text), that would made a good testing base for this code.

API

Exposed in bpy.utils.units. For now, I kept it simple:

*str_to_value(unit_system, unit_type, str_input, str_ref_unit=None) to parse string into a float value.
*value_to_str(unit_system, unit_type, value, precision=3, split_unit=False, compatible_unit=False) to print a float value into a string with units.
*systems is a named tuple gathering all known unit systems ('NONE', 'METRIC', etc.).
*types is a named tuple gathering all known unit types ('LENGTH', 'AREA', 'ROTATION', etc.).

Tests

Tests are a mere tuple of tuples.

For each input test, you have:

  (unit_system,     # 'NONE', 'METRIC' or 'IMPERIAL'.
   unit_type,       # E.g. 'LENGTH', 'AREA', 'ROTATION', etc.
   ref_string,      # optional (can be empty), a reference string from which to take a unit, if none is found in str
                  # (e.g. for num buttons, it is the previous string displayed...).
   str,             # The string to convert to a float value.
   expected_value,  # The expected value.
  )

This mimics current parameters of new bpy.utils.units.str_to_value function.
E.g.: ('IMPERIAL', 'LENGTH', "", "1ft", 0.3048)

For each output test, you have:

  (unit_system,   # As above.
   unit_type,     # As above.
   precision,     # Number of digits after the comma.
   split_unit,    # If True, output e.g. '1m1cm', else output e.g. '1.01m'.
   compat_unit,   # If True, only use simple chars in units (e.g. '1m2'), else use nicer ones (e.g. '1m²').
   value,         # Input value to convert to a string.
   expected_str,  # Expected string result.
  )

This mimics current parameters of new bpy.utils.units.value_to_str function.
E.g.: ('IMPERIAL', 'LENGTH', 3, False, False, 0.3048, "1'")

# Implement UnitTesting for UI Units handling, and improve it So, related to #38722 and proposed fix ([D340](https://archive.blender.org/developer/D340)), I talked a bit with Campbell and he suggested to first expose 'units' in bpy, and create a test for it. Test should gather a bunch of expressions and their desired result, to check what's currently working, what’s currently broken, and how this change when we modify underlying C code. I made a quick prototype for this: [D416](https://archive.blender.org/developer/D416). For now, it only contains trivial tests (two input, one know as broken, and one output). The main purpose of this design task is to gather a representative set of inputs (text to value) and outputs (value to text), that would made a good testing base for this code. ## API Exposed in `bpy.utils.units`. For now, I kept it simple: *`str_to_value(unit_system, unit_type, str_input, str_ref_unit=None)` to parse string into a float value. *`value_to_str(unit_system, unit_type, value, precision=3, split_unit=False, compatible_unit=False)` to print a float value into a string with units. *`systems` is a named tuple gathering all known unit systems ('NONE', 'METRIC', etc.). *`types` is a named tuple gathering all known unit types ('LENGTH', 'AREA', 'ROTATION', etc.). ## Tests Tests are a mere tuple of tuples. For each input test, you have: ``` (unit_system, # 'NONE', 'METRIC' or 'IMPERIAL'. unit_type, # E.g. 'LENGTH', 'AREA', 'ROTATION', etc. ref_string, # optional (can be empty), a reference string from which to take a unit, if none is found in str ``` # (e.g. for num buttons, it is the previous string displayed...). ``` str, # The string to convert to a float value. expected_value, # The expected value. ) ``` This mimics current parameters of new `bpy.utils.units.str_to_value` function. E.g.: `('IMPERIAL', 'LENGTH', "", "1ft", 0.3048)` For each output test, you have: ``` (unit_system, # As above. unit_type, # As above. precision, # Number of digits after the comma. split_unit, # If True, output e.g. '1m1cm', else output e.g. '1.01m'. compat_unit, # If True, only use simple chars in units (e.g. '1m2'), else use nicer ones (e.g. '1m²'). value, # Input value to convert to a string. expected_str, # Expected string result. ) ``` This mimics current parameters of new `bpy.utils.units.value_to_str` function. E.g.: `('IMPERIAL', 'LENGTH', 3, False, False, 0.3048, "1'")`
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Bastien Montagne self-assigned this 2014-03-19 16:37:42 +01:00
Author
Owner

Added subscribers: @mont29, @JonathanWilliamson, @ideasman42

Added subscribers: @mont29, @JonathanWilliamson, @ideasman42
Author
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Owner

Fixed/closed by 8535b9bd15.

Fixed/closed by 8535b9bd15.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#39267
No description provided.