Skip to content

Commit

Permalink
feat: updated robot keywords class (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
shpaker authored Nov 20, 2024
1 parent 59b5a01 commit 6fbe6c8
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.py]
[*.{py,robot}]
indent_size = 4

[*.{md,txt,rst}]
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Lint

on:
pull_request:
branches: [ main ]

jobs:
lint:
runs-on: windows-latest
strategy:
matrix:
PYTHON_VERSION:
# - "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
steps:
- uses: extractions/setup-just@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.PYTHON_VERSION }}
- uses: actions/checkout@v4
- run: |
python -m pip install poetry~=1.8.4
poetry install --no-ansi
- run: just tests
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.PYTHON_VERSION }}_log.html
path: log.html
17 changes: 10 additions & 7 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
SOURCE_DIR := "winregistry.py"
SOURCE_FILE := "winregistry.py"
TESTS_FILE := "winregistry_tests.robot"

tests: pytest
tests: robot
fmt: black isort

isort:
poetry run isort {{ SOURCE_DIR }}
poetry run isort {{ SOURCE_FILE }}

black:
poetry run black {{ SOURCE_DIR }}

poetry run black {{ SOURCE_FILE }}

pytest:
poetry run pytest -vv

ruff:
poetry run ruff check --fix {{SOURCE_DIR}}
poetry run ruff check --fix {{ SOURCE_FILE }}

mypy:
poetry run mypy --pretty {{SOURCE_DIR}}
poetry run mypy --pretty {{ SOURCE_FILE }}

robot:
poetry run robot {{ TESTS_FILE }}
95 changes: 47 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,12 @@ Install via PyPI:
pip install winregistry
```

## QuickStart

```python
import winreg
import winregistry

KEY_NAME_FOR_TESTING = 'HKLM\SOFTWARE\_REMOVE_ME_'

# create key
winregistry.create_key(KEY_NAME_FOR_TESTING)
winregistry.create_key(f'{KEY_NAME_FOR_TESTING}\some_subkey')
print(list(winregistry.child_keys_names(f'{KEY_NAME_FOR_TESTING}\_REMOVE_ME_')))

# manipulations with values
winregistry.values_names(KEY_NAME_FOR_TESTING)
winregistry.set_value(KEY_NAME_FOR_TESTING, 'smth', winreg.REG_SZ, 'some data')
winregistry.values_names(KEY_NAME_FOR_TESTING)
with winregistry.read_value(KEY_NAME_FOR_TESTING, 'smth') as value:
value.data = 'updated data!'
print(winregistry.read_value_data(KEY_NAME_FOR_TESTING, 'smth'))
winregistry.delete_value(KEY_NAME_FOR_TESTING, 'smth')

# delete key
winregistry.delete_key(f'{KEY_NAME_FOR_TESTING}\some_subkey')
winregistry.delete_key(KEY_NAME_FOR_TESTING)
```

## Advances usage

```python
import winreg
from winregistry import open_key

# connect to registry
with open_key(
winreg.HKEY_LOCAL_MACHINE,
) as hklm:
...

# connect to registry and open sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
...

# connect to registry and ensure sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
Expand All @@ -71,17 +31,10 @@ with open_key(

# also you can connect to registry with string key
with open_key(
"HKLM\SOFTWARE",
"HKLM\SOFTWARE\_REMOVE_ME_",
) as key:
...

# open key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
) as hklm:
with hklm.open_key("SOFTWARE"):
...

# create or open sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
Expand Down Expand Up @@ -133,3 +86,49 @@ with open_key(
) as key:
value = key.delete_value("remove_me")
```

## Usage with `Robot Testing Framework`

```robotframework
*** Variables ***
${SUITE_KEY_NAME} HKLM\\SOFTWARE\\_ROBOT_TESTS_
${SHORT_CASE_KEY_NAME} _CASE_KEY_
${CASE_KEY_NAME} ${SUITE_KEY_NAME}\\${SHORT_CASE_KEY_NAME}
${VALUE_NAME} some_testing_value
*** Settings ***
Library Collections
Library winregistry.robot
Suite Setup Create Registry Key ${ SUITE_KEY_NAME }
Suite Teardown Delete Registry Key ${ SUITE_KEY_NAME }
*** Test Cases ***
TEST REGISTRY KEYS
[Teardown] Delete Registry Key ${CASE_KEY_NAME}
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Not Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
Registry Key Should Not Exist ${ CASE_KEY_NAME }
Create Registry Key ${ CASE_KEY_NAME }
Registry Key Should Exist ${ CASE_KEY_NAME }
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
TEST REGISTRY VALUES
[Setup] Create Registry Key ${ CASE_KEY_NAME }
[Teardown] Delete Registry Key ${ CASE_KEY_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Not Contain Value ${ items } ${ VALUE_NAME }
Registry Value Should Not Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ
Registry Value Should Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Contain Value ${ items } ${ VALUE_NAME }
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } ${ EMPTY }
Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ foo
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } foo
```
Loading

0 comments on commit 6fbe6c8

Please sign in to comment.