Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/tests/test_legends.py
2313 views
1
import pathlib
2
import tempfile
3
import textwrap
4
import unittest
5
from geemap import legends
6
7
8
class LegendsTest(unittest.TestCase):
9
10
def test_ee_table_to_legend(self):
11
in_table_content = textwrap.dedent("""\
12
Value\tColor\tDescription
13
11\t466b9f\tOpen Water
14
12\td1def8\tPerennial Ice/Snow
15
21\tdec5c5\tDeveloped, Open Space
16
""")
17
expected_output = textwrap.dedent("""\
18
{
19
\t'11 Open Water': '466b9f',
20
\t'12 Perennial Ice/Snow': 'd1def8',
21
\t'21 Developed, Open Space': 'dec5c5'
22
}
23
""")
24
25
with tempfile.TemporaryDirectory() as tmpdir:
26
tmpdir = pathlib.Path(tmpdir)
27
in_table_path = tmpdir / "in_table.txt"
28
out_file_path = tmpdir / "out_file.txt"
29
30
in_table_path.write_text(in_table_content)
31
legends.ee_table_to_legend(str(in_table_path), str(out_file_path))
32
33
actual_output = out_file_path.read_text()
34
self.assertEqual(expected_output, actual_output)
35
36
37
if __name__ == "__main__":
38
unittest.main()
39
40