from attest import Assert, Tests, TestBase, test

import pyhis


class TWDBTestBase(TestBase):
    """Base class for using TWDB dataset as a source"""

    @test
    def check_sites(self):
        assert Assert(len(self.source.sites)) == 74

    @test
    def check_variables(self):
        assert Assert(len(self.source.sites['Aransas95_D1'].variables)) == 5

    @test
    def check_dataframe(self):
        df = self.source.sites['Aransas95_D1'].dataframe
        assert Assert(len(df['SAL001'])) == 706


class TWDBCacheTests(TWDBTestBase):
    """
    Run tests with cache backend
    """

    def __context__(self):
        self.source = pyhis.Source(
            'http://his.crwr.utexas.edu/TWDB_Sondes/cuahsi_1_0.asmx?WSDL',
            use_cache=True)
        yield
        del self.source


class TWDBNoCacheTests(TWDBTestBase):
    """
    Run tests without cache backend
    """

    def __context__(self):
        self.source = pyhis.Source(
            'http://his.crwr.utexas.edu/TWDB_Sondes/cuahsi_1_0.asmx?WSDL',
            use_cache=False)
        yield
        del self.source


if __name__ == '__main__':
    suite = Tests([TWDBCacheTests(), TWDBNoCacheTests()])
    suite.run()

@@ -1,8 +1,19 @@
+import os%0A%0A
 from att
@@ -513,16 +513,428 @@
 = 706%0A%0A%0A
+class TWDBFreshCacheTests(TWDBTestBase):%0A    %22%22%22%0A    Run tests with cache backend%0A    %22%22%22%0A%0A    def __context__(self):%0A        if os.path.exists(pyhis.cache.CACHE_DATABASE_FILE):%0A            os.remove(pyhis.cache.CACHE_DATABASE_FILE)%0A        self.source = pyhis.Source(%0A            'http://his.crwr.utexas.edu/TWDB_Sondes/cuahsi_1_0.asmx?WSDL',%0A            use_cache=True)%0A        yield%0A        del self.source%0A%0A%0A
 class TW
@@ -1561,24 +1561,29 @@
  Tests(%5BTWDB
+Fresh
 CacheTests()
@@ -1583,16 +1583,72 @@
 Tests(),
+%0A                   TWDBCacheTests(),%0A                  
  TWDBNoC

add tests for a fresh cache (no cache db exists)