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

'GreenStream' object has no attribute 'encoding' #203

Closed
fchauvel opened this issue Apr 3, 2019 · 3 comments
Closed

'GreenStream' object has no attribute 'encoding' #203

fchauvel opened this issue Apr 3, 2019 · 3 comments

Comments

@fchauvel
Copy link
Contributor

fchauvel commented Apr 3, 2019

I'm currently migrating my CAMP application from Python 2.7 to Python 3.5.3 (on Debian 9) and I now get several tests that fail only when I use green (they pass if I run a python setup.py test -s tests.generate.test_samples.

See the logs I get below using green. The output intercepted by Green shows that the z3 module (which we depend on) tried to access the 'encoding' attribute of sys.stdout

$ green -qfvv -d tests.generate.test_samples
2019-04-03 15:31:29     DEBUG Attempting to load target 'tests.generate.test_samples' with file_pattern 'test*.py'
2019-04-03 15:31:30     DEBUG Test case names: ['test_orchestrations', 'test_single_component', 'test_stack', 'test_variables']
2019-04-03 15:31:30     DEBUG Test case names: []
2019-04-03 15:31:30     DEBUG Load method: DOTTED OBJECT - tests.generate.test_samples
2019-04-03 15:31:30     DEBUG Found 4 tests for target 'tests.generate.test_samples'
2019-04-03 15:31:30     DEBUG Sending tests.generate.test_samples to runner <function poolRunner at 0x7f98dae526a8>
2019-04-03 15:31:30     DEBUG Attempting to load target 'tests.generate.test_samples' with file_pattern 'test*.py'
2019-04-03 15:31:30     DEBUG Test case names: ['test_orchestrations', 'test_single_component', 'test_stack', 'test_variables']
2019-04-03 15:31:30     DEBUG Test case names: []
2019-04-03 15:31:30     DEBUG Load method: DOTTED OBJECT - tests.generate.test_samples
2019-04-03 15:31:30     DEBUG Found 4 tests for target 'tests.generate.test_samples'
E

Error in tests.generate.test_samples.FilesAreGenerated.test_orchestrations
  File "/usr/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.5/unittest/case.py", line 601, in run
    testMethod()
  File "/home/fchauvel/Documents/camp/tests/generate/test_samples.py", line 108, in test_orchestrations
    self.assert_configuration_count_is(2)
  File "/home/fchauvel/Documents/camp/tests/generate/test_samples.py", line 127, in assert_configuration_count_is
    for each_file in listdir(destination):
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp6ba9wovk/camp_fzcika6m/generate/out'

Captured stdout for tests.generate.test_samples.FilesAreGenerated.test_orchestrations
CAMP v0.3.1 (MIT)
Copyright (C) 2017 -- 2019 SINTEF Digital

Loaded '/tmp/tmp6ba9wovk/camp_fzcika6m/generate/camp.yaml'.
Unexpected error:
 - 'GreenStream' object has no attribute 'encoding'
   In file: /usr/lib/python3.5/z3/z3core.py
      82: enc = sys.stdout.encoding
   Please report this at 'https://github.com/STAMP-project/camp/issues'.

That's all folks!

Captured stderr for tests.generate.test_samples.FilesAreGenerated.test_orchestrations
/home/fchauvel/Documents/camp/camp/generate.py:214: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  metamodel = load_yaml(data)

Warning: Some tests may not have been run.

Ran 1 test in 0.107s

FAILED (errors=1)

By contrast the tests pass when I do not use green:

$ python setup.py test -s tests.generate.test_samples
running test
running egg_info
writing entry points to camp.egg-info/entry_points.txt
writing camp.egg-info/PKG-INFO
writing dependency_links to camp.egg-info/dependency_links.txt
writing requirements to camp.egg-info/requires.txt
writing top-level names to camp.egg-info/top_level.txt
reading manifest file 'camp.egg-info/SOURCES.txt'
writing manifest file 'camp.egg-info/SOURCES.txt'
running build_ext
test_orchestrations (tests.generate.test_samples.FilesAreGenerated) ... /home/fchauvel/Documents/camp/camp/generate.py:214: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  metamodel = load_yaml(data)
ok
test_single_component (tests.generate.test_samples.FilesAreGenerated) ... ok
test_stack (tests.generate.test_samples.FilesAreGenerated) ... ok
test_variables (tests.generate.test_samples.FilesAreGenerated) ... ok

----------------------------------------------------------------------
Ran 4 tests in 1.879s

OK

Looking at the past issues, I guess this somehow similar to Issue #146. As explained, the command green -a works as a workaround but it would be nice to be able to capture output :-)

Thanks anyway.

@CleanCut
Copy link
Owner

CleanCut commented Apr 4, 2019

Your guess was correct! This was very similar to #146.

I added an encoding attribute to our wrapped sys.stdout that mirrors the value of what we're wrapping. I tested it on your Camp application and it worked for me. The fix is in Green 2.14.2 (just released).

@fchauvel
Copy link
Contributor Author

fchauvel commented Apr 5, 2019

Works just fine now! Many thanks for the quick fix!

fchauvel added a commit to STAMP-project/camp that referenced this issue Apr 5, 2019
@CleanCut
Copy link
Owner

CleanCut commented Apr 5, 2019

Works just fine now! Many thanks for the quick fix!

You're welcome! It is always nice when the solution is so straightforward. That's fairly rare in my experience. 😄

jesus-gorronogoitia pushed a commit to STAMP-project/camp that referenced this issue Nov 18, 2021
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

No branches or pull requests

2 participants