Skip to content

Conversation

@rytilahti
Copy link
Member

@rytilahti rytilahti commented Nov 17, 2022

I created this script earlier to test the idea of having module-specific fixture files for testing, but never had time to finish working on that. This draft is created just to not forget about it completely.

Usage: create_module_fixtures.py [OPTIONS] OUTPUTDIR

  Create module fixtures for given host/network.

Arguments:
  OUTPUTDIR  [required]

Options:
  --host TEXT
  --network TEXT
  --install-completion  Install completion for the current shell.
  --show-completion     Show completion for the current shell, to copy it or
                        customize the installation.
  --help                Show this message and exit.

for example:

python create_module_fixtures.py --network 192.168.4.255 /tmp/testfix

will create files from the given network under /tmp/testfix/:

ls -alR /tmp/testfix/

❯ ls -alR /tmp/testfix/
drwxr-xr-x - tpr 17 Nov 21:38 antitheft
drwxr-xr-x - tpr 17 Nov 21:38 cloud
drwxr-xr-x - tpr 17 Nov 21:38 countdown
drwxr-xr-x - tpr 17 Nov 21:38 emeter
drwxr-xr-x - tpr 17 Nov 21:38 schedule
drwxr-xr-x - tpr 17 Nov 21:38 time
drwxr-xr-x - tpr 17 Nov 21:38 usage

/tmp/testfix/antitheft:
.rw-r--r-- 816 tpr 17 Nov 21:38 HS110(EU)_1.0_1.2.5.json
.rw-r--r-- 214 tpr 17 Nov 21:38 HS110(EU)_4.0_1.0.4.json
.rw-r--r-- 214 tpr 17 Nov 21:38 KP115(EU)_1.0_1.0.16.json
.rw-r--r-- 214 tpr 17 Nov 21:38 KP303(UK)_1.0_1.0.3.json

/tmp/testfix/cloud:
.rw-r--r-- 320 tpr 17 Nov 21:38 HS110(EU)_1.0_1.2.5.json
.rw-r--r-- 320 tpr 17 Nov 21:38 HS110(EU)_4.0_1.0.4.json
.rw-r--r-- 320 tpr 17 Nov 21:38 KP115(EU)_1.0_1.0.16.json
cat /tmp/testfix/cloud/HS110\(EU\)_1.0_1.2.5.json 
{
    "get_info": {
        "username": "",
        "server": "devs.tplinkcloud.com",
        "binded": 0,
        "cld_connection": 0,
        "illegalType": -1,
        "stopConnect": -1,
        "tcspStatus": -1,
        "fwDlPage": "",
        "tcspInfo": "",
        "fwNotifyType": 0,
        "err_code": 0
    }
}

@jules43
Copy link
Contributor

jules43 commented Nov 19, 2022

Dumb question: Where does the data come from for the fixtures being generated? Is this tool extracting it from larger fixture files, pulling it from actual devices or generating it from code or other data?

@rytilahti
Copy link
Member Author

They are being pulled from the device, the script just makes an update for the given device (or all discovered devices, if using --network), reads the internal data (using https://github.com/python-kasa/python-kasa/blob/master/kasa/modules/module.py#L47) from each of the supported modules, and saves it into a separate JSON file.

@rytilahti rytilahti marked this pull request as ready for review August 27, 2023 17:42
@rytilahti rytilahti added the enhancement New feature or request label Aug 27, 2023
@codecov-commenter
Copy link

Codecov Report

Patch coverage has no change and project coverage change: +0.32% 🎉

Comparison is base (ad5b5c2) 79.02% compared to head (0cfe4d6) 79.34%.
Report is 37 commits behind head on master.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
+ Coverage   79.02%   79.34%   +0.32%     
==========================================
  Files          24       26       +2     
  Lines        1821     1980     +159     
  Branches      266      613     +347     
==========================================
+ Hits         1439     1571     +132     
- Misses        348      367      +19     
- Partials       34       42       +8     

see 13 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rytilahti
Copy link
Member Author

I think there is no harm merging this as it may be useful for someone even when there are currently no tests for individual modules.

@rytilahti rytilahti merged commit fad6ae5 into python-kasa:master Aug 27, 2023
@rytilahti rytilahti deleted the feat/add_create_module_fixtures branch August 27, 2023 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants