Skip to content

Commit

Permalink
Fix test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
tkeffer committed Jan 26, 2023
1 parent 64d7630 commit 602baa5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 68 deletions.
13 changes: 0 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@


## Commands
```
✅ weectl station create
✅ weectl station reconfigure
✅ weectl station upgrade
✅ weectl station upgrade-skins
✅ weectl extension install
✅ weectl extension uninstall
✅ weectl extension list
✅ weectl extension transfer
```
Key:
✅ means completed
½ means started

## Utilities

Expand Down
37 changes: 19 additions & 18 deletions bin/weecfg/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
[section_e]
c = 15"""

current_config_dict_path = "../../wee_resources/weewx.conf"
import wee_resources
resource_dir = os.path.dirname(wee_resources.__file__)
current_config_dict_path = os.path.join(resource_dir, 'weewx.conf')


def suppress_stdout(func):
Expand Down Expand Up @@ -311,7 +313,8 @@ def _build_mini_weewx(weewx_root):
shutil.rmtree(weewx_root, ignore_errors=True)
os.makedirs(os.path.join(weewx_root, 'skins'))
# Copy over the current version of the 'user' package
shutil.copytree('../../../bin/user', os.path.join(weewx_root, 'user'))
shutil.copytree(os.path.join(resource_dir, 'bin/user'),
os.path.join(weewx_root, 'user'))
# Copy over the current version of weewx.conf
shutil.copy(current_config_dict_path, weewx_root)

Expand All @@ -331,38 +334,36 @@ def setUp(self):
# non-standard location.
self.engine = weecfg.extension.ExtensionEngine(self.config_path,
self.config_dict,
bin_root=self.weewx_root,
logger=weecfg.Logger(verbosity=-1))

def tearDown(self):
"Remove any installed test configuration"
shutil.rmtree(self.weewx_root, ignore_errors=True)

def test_install(self):

# Make sure the root dictionary got calculated correctly:
self.assertEqual(self.engine.root_dict['WEEWX_ROOT'], '/var/tmp/wee_test')
self.assertEqual(self.engine.root_dict['USER_ROOT'], '/var/tmp/wee_test/user')
self.assertEqual(self.engine.root_dict['EXT_ROOT'], '/var/tmp/wee_test/user/installer')
self.assertEqual(self.engine.root_dict['SKIN_ROOT'], '/var/tmp/wee_test/skins')
self.assertEqual(self.engine.root_dict['CONFIG_ROOT'], '/var/tmp/wee_test')
self.assertEqual(self.engine.root_dict['USER_DIR'], '/var/tmp/wee_test/bin/user')
self.assertEqual(self.engine.root_dict['BIN_DIR'], '/var/tmp/wee_test/bin')
self.assertEqual(self.engine.root_dict['EXT_DIR'], '/var/tmp/wee_test/bin/user/installer')
self.assertEqual(self.engine.root_dict['SKIN_DIR'], '/var/tmp/wee_test/skins')

# Now install the extension...
self.engine.install_extension('./pmon.tgz')

# ... and assert that it got installed correctly
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['USER_ROOT'],
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['USER_DIR'],
'pmon.py')))
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['USER_ROOT'],
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['USER_DIR'],
'installer',
'pmon',
'install.py')))
self.assertTrue(os.path.isdir(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertTrue(os.path.isdir(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon')))
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon',
'index.html.tmpl')))
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertTrue(os.path.isfile(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon',
'skin.conf')))

Expand Down Expand Up @@ -392,18 +393,18 @@ def test_uninstall(self):
self.engine.uninstall_extension('pmon')

# Assert that everything got removed correctly:
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['USER_ROOT'],
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['USER_DIR'],
'pmon.py')))
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['USER_ROOT'],
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['USER_DIR'],
'installer',
'pmon',
'install.py')))
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon')))
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon',
'index.html.tmpl')))
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_ROOT'],
self.assertFalse(os.path.exists(os.path.join(self.engine.root_dict['SKIN_DIR'],
'pmon',
'skin.conf')))

Expand Down
4 changes: 2 additions & 2 deletions bin/weewx/tests/expected/StandardTest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,14 @@ <h1>Test for tag $seven_day</h1>
<tr>
<td align="right">Max temp from $seven_day.outTemp.max</td>
<td align="left">82.7&#176;F <br/>
at 16:00 on Friday</td>
at 27-Aug-2010 16:00</td>
</tr>
<tr>
<td align="right">High Wind from "$seven_day.wind.max"</td>
<td align="left">
24 mph <br/>
from 90&#176; <br/>
at 01:00 on Monday
at 30-Aug-2010 01:00
</td>
</tr>
</table>
Expand Down
4 changes: 2 additions & 2 deletions bin/weewx/tests/expected/StandardTest/metric/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,14 @@ <h1>Test for tag $seven_day</h1>
<tr>
<td align="right">Max temp from $seven_day.outTemp.max</td>
<td align="left">28.2&#176;C <br/>
at 16:00 on Friday</td>
at 27-Aug-2010 16:00</td>
</tr>
<tr>
<td align="right">High Wind from "$seven_day.wind.max"</td>
<td align="left">
39 kph <br/>
from 90&#176; <br/>
at 01:00 on Monday
at 30-Aug-2010 01:00
</td>
</tr>
</table>
Expand Down
16 changes: 0 additions & 16 deletions bin/weewx/tests/test_reportengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#
"""Test algorithms in the Report Engine"""

import importlib.resources
import logging
import os.path
import sys
import unittest

import weeutil.config
Expand Down Expand Up @@ -39,20 +37,6 @@
CONFIG_DICT = weeutil.config.config_from_str(CONFIG_DICT_INI)
CONFIG_DICT['WEEWX_ROOT'] = os.path.normpath(os.path.join(os.path.dirname(__file__), '../../..'))

# For MacOS, the default logging logs to /var/log/weewx.log, which is a privileged location.
# Change to something unprivileged, so we don't have to run test suites as root.
if sys.platform == 'darwin':
LOGGING = {
'Logging': {
'handlers': {
'rotate': {
'filename': '/var/tmp/weewx.log'
}
}
}
}
CONFIG_DICT.merge(LOGGING)

weeutil.logger.setup('test_reportengine', CONFIG_DICT)


Expand Down
2 changes: 1 addition & 1 deletion bin/weewx/tests/test_skins/StandardTest/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
encoding = html_entities # Possible encodings are 'html_entities', 'utf8', or 'strict_ascii'

# We will be testing SLEs as well. Might as well test the example included in the manual:
search_list_extensions = seven_day.SevenDay, colorize_1.Colorize, colorize_2.Colorize, colorize_3.Colorize
search_list_extensions = xstats.ExtendedStatistics, colorize_1.Colorize, colorize_2.Colorize, colorize_3.Colorize

[[SummaryByHours]]
#
Expand Down
20 changes: 4 additions & 16 deletions bin/weewx/tests/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009-2022 Tom Keffer <tkeffer@gmail.com>
# Copyright (c) 2009-2023 Tom Keffer <tkeffer@gmail.com>
#
# See the file LICENSE.txt for your full rights.
#
"""Test tag notation for template generation.
To run standalone, PYTHONPATH must be set to not only the WeeWX code, but also the "stats" example.
Something like:
cd ~/git/weewx
PYTHONPATH="./examples:./bin" python bin/weewx/tests/test_templates.py
"""

from __future__ import absolute_import
from __future__ import print_function
from __future__ import with_statement
"""Test tag notation for template generation."""

import locale
import logging
Expand All @@ -26,12 +15,11 @@
import unittest

import configobj
from six.moves import map

import gen_fake_data
import weeutil.config
import weeutil.logger
import weeutil.weeutil
import weeutil.config
import weewx
import weewx.accum
import weewx.reportengine
Expand Down Expand Up @@ -76,8 +64,8 @@
import wee_resources
example_dir = os.path.normpath(os.path.join(os.path.dirname(wee_resources.__file__),
'./examples'))
sys.path.append(example_dir)
sys.path.append(os.path.join(example_dir, './colorize'))
sys.path.append(os.path.join(example_dir, './xstats/bin/user'))

import colorize_1
import colorize_2
Expand Down

0 comments on commit 602baa5

Please sign in to comment.