Browse Source

Add nilm-copy-wildcard test

tags/nilmtools-2.0.0
Jim Paris 1 year ago
parent
commit
feb12ecfc1
2 changed files with 46 additions and 1 deletions
  1. +1
    -1
      nilmtools/copy_wildcard.py
  2. +45
    -0
      tests/test.py

+ 1
- 1
nilmtools/copy_wildcard.py View File

@@ -67,7 +67,7 @@ def main(argv = None):
nilmtools.copy_one.main(new_argv)
except SystemExit as e:
# Ignore SystemExit which could be raised on --dry-run
if e.code != 0:
if e.code != 0: # pragma: no cover (shouldn't happen)
raise

if __name__ == "__main__":


+ 45
- 0
tests/test.py View File

@@ -220,6 +220,51 @@ class TestAllCommands(CommandTester):
def test_02_copy_wildcard(self):
self.main = nilmtools.copy_wildcard.main

client1 = nilmdb.client.Client(url=self.url)
client2 = nilmdb.client.Client(url=self.url2)

# basic arguments
self.fail(f"")
self.fail(f"/newton")

self.fail(f"-u {self.url} -U {self.url} /newton")
self.contain("URL must be different")

# no matches; silent
self.ok(f"-u {self.url} -U {self.url2} /newton")
self.ok(f"-u {self.url} -U {self.url2} /asdf*")
self.ok(f"-u {self.url2} -U {self.url} /newton*")
eq_(client2.stream_list(), [])

# this won't actually copy, but will still create streams
self.ok(f"-u {self.url} -U {self.url2} --dry-run /newton*")
self.contain("Creating destination stream /newton/prep-copy")
eq_(len(list(client2.stream_extract("/newton/prep"))), 0)

# this should copy a bunch
self.ok(f"-u {self.url} -U {self.url2} /newton*")
self.contain("Creating destination stream /newton/prep-copy", False)
eq_(client1.stream_list(), client2.stream_list())
eq_(list(client1.stream_extract("/newton/prep")),
list(client2.stream_extract("/newton/prep")))
eq_(client1.stream_get_metadata("/newton/prep"),
client2.stream_get_metadata("/newton/prep"))

# repeating it is OK; it just won't recreate streams.
# Let's try with --nometa too
client2.stream_remove("/newton/prep")
client2.stream_destroy("/newton/prep")
self.ok(f"-u {self.url} -U {self.url2} --nometa /newton*")
self.contain("Creating destination stream /newton/prep-copy", False)
self.contain("Creating destination stream /newton/prep", True)
eq_(client1.stream_list(), client2.stream_list())
eq_(list(client1.stream_extract("/newton/prep")),
list(client2.stream_extract("/newton/prep")))
eq_(client2.stream_get_metadata("/newton/prep"), {})

# fill in test cases
self.ok(f"-u {self.url} -U {self.url2} -s 2010 -e 2020 -F /newton*")

def test_03_decimate(self):
self.main = nilmtools.decimate.main



Loading…
Cancel
Save