i3pystatus icon indicating copy to clipboard operation
i3pystatus copied to clipboard

Testing modifications/additions to modules

Open 211217613 opened this issue 8 years ago • 6 comments

I'm trying to add a click event to an existing module (temp.py). I cloned the repo and made changes there. How do I test the changes I've made?

211217613 avatar May 19 '16 01:05 211217613

I usually just run i3pystatus straight from the git repo. When I want to test changes to a module I'll just reload i3 to make them take effect. I'd be interested to hear if anyone has any clever ways of testing though.

facetoe avatar May 19 '16 10:05 facetoe

Development environment: Use a virtualenv (per project)

Testing: running from the virtualenv, either i3pystatus / a test script or the unit tests (classic unit testing would be a mocking orgy for many modules in this project so most modules are only practically tested and not covered by unit tests)

enkore avatar May 19 '16 10:05 enkore

I usually install projects relying on distutils via: python setup.py develop --user This creates symlinks and let your package correctly discover python namespaces.

teto avatar May 19 '16 12:05 teto

@facetoe I'm pretty sure Ipip installedor apt-get installed and I also git cloned... How do I run i3pystatus from the git cloned location?

211217613 avatar May 23 '16 01:05 211217613

@211217613 I'd uninstall the code installed from apt and pip then use setup.py as teto suggests above.

facetoe avatar May 23 '16 10:05 facetoe

@211217613 Running python from git repo directory should do the trick.

Ipython for ilustration:

In [1]: cd '~/git/i3pystatus/'
/home/luck/git/i3pystatus

In [2]: import i3pystatus

In [3]: i3pystatus?
Type:        module
String form: <module 'i3pystatus' from '/home/luck/git/i3pystatus/i3pystatus/__init__.py'>
File:        ~/git/i3pystatus/i3pystatus/__init__.py
Docstring:   <no docstring>

Something usable in i3 config file:

bar {
  status_command bash -c 'cd /home/luck/git/i3pystatus && python testing_config.py'
}

Just make sure that your testing_config.py is an actuall file inside the git repo directory and not a symlink.

EDIT: Also a method how to test changes that was not mentioned yet: Modify end of your testing_config.py file to look like this:

if __name__ == "__main__":
    status.run()

then run ipython from repo directory and import testing_config

In [1]: from testing_config import *

In [2]: status.modules[2]
Out[2]: <i3pystatus.clock.Clock at 0x7fb65327e160>

In [3]: status.modules[2].run(); status.modules[2].output
Out[3]: {'color': '#ffffff', 'full_text': 'Po 23 máj 13:14:35', 'urgent': False}

richese avatar May 23 '16 11:05 richese